mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-04-29 19:21:14 +00:00
Implement dark mode using style sheets
This commit is contained in:
@@ -239,35 +239,28 @@ def plot_entries(entries, title=None, output=None, dark=False):
|
|||||||
colors = [bench_colors[bench] for bench in bench_names]
|
colors = [bench_colors[bench] for bench in bench_names]
|
||||||
|
|
||||||
fig_height = max(4.0, 0.3 * len(entries) + 1.5)
|
fig_height = max(4.0, 0.3 * len(entries) + 1.5)
|
||||||
fig, ax = plt.subplots(figsize=(10, fig_height))
|
style = "dark_background" if dark else None
|
||||||
if dark:
|
with plt.style.context(style) if style else plt.style.context("default"):
|
||||||
fig.patch.set_facecolor("black")
|
fig, ax = plt.subplots(figsize=(10, fig_height))
|
||||||
ax.set_facecolor("black")
|
|
||||||
ax.tick_params(colors="white")
|
|
||||||
ax.xaxis.label.set_color("white")
|
|
||||||
ax.yaxis.label.set_color("white")
|
|
||||||
ax.title.set_color("white")
|
|
||||||
for spine in ax.spines.values():
|
|
||||||
spine.set_color("white")
|
|
||||||
|
|
||||||
y_pos = range(len(labels))
|
y_pos = range(len(labels))
|
||||||
ax.barh(y_pos, values, color=colors)
|
ax.barh(y_pos, values, color=colors)
|
||||||
ax.set_yticks(y_pos)
|
ax.set_yticks(y_pos)
|
||||||
ax.set_yticklabels(labels)
|
ax.set_yticklabels(labels)
|
||||||
ax.invert_yaxis()
|
ax.invert_yaxis()
|
||||||
ax.set_ylim(len(labels) - 0.5, -0.5)
|
ax.set_ylim(len(labels) - 0.5, -0.5)
|
||||||
|
|
||||||
ax.xaxis.set_major_formatter(PercentFormatter(1.0))
|
ax.xaxis.set_major_formatter(PercentFormatter(1.0))
|
||||||
|
|
||||||
if title:
|
if title:
|
||||||
ax.set_title(title)
|
ax.set_title(title)
|
||||||
|
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
fig.savefig(output, dpi=150)
|
fig.savefig(output, dpi=150)
|
||||||
else:
|
else:
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user