Skip to content

Commit 28ed32b

Browse files
Implement dark mode using style sheets
1 parent ec97590 commit 28ed32b

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

python/scripts/nvbench_plot.py

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -239,35 +239,28 @@ def plot_entries(entries, title=None, output=None, dark=False):
239239
colors = [bench_colors[bench] for bench in bench_names]
240240

241241
fig_height = max(4.0, 0.3 * len(entries) + 1.5)
242-
fig, ax = plt.subplots(figsize=(10, fig_height))
243-
if dark:
244-
fig.patch.set_facecolor("black")
245-
ax.set_facecolor("black")
246-
ax.tick_params(colors="white")
247-
ax.xaxis.label.set_color("white")
248-
ax.yaxis.label.set_color("white")
249-
ax.title.set_color("white")
250-
for spine in ax.spines.values():
251-
spine.set_color("white")
252-
253-
y_pos = range(len(labels))
254-
ax.barh(y_pos, values, color=colors)
255-
ax.set_yticks(y_pos)
256-
ax.set_yticklabels(labels)
257-
ax.invert_yaxis()
258-
ax.set_ylim(len(labels) - 0.5, -0.5)
259-
260-
ax.xaxis.set_major_formatter(PercentFormatter(1.0))
261-
262-
if title:
263-
ax.set_title(title)
264-
265-
fig.tight_layout()
266-
267-
if output:
268-
fig.savefig(output, dpi=150)
269-
else:
270-
plt.show()
242+
style = "dark_background" if dark else None
243+
with plt.style.context(style) if style else plt.style.context("default"):
244+
fig, ax = plt.subplots(figsize=(10, fig_height))
245+
246+
y_pos = range(len(labels))
247+
ax.barh(y_pos, values, color=colors)
248+
ax.set_yticks(y_pos)
249+
ax.set_yticklabels(labels)
250+
ax.invert_yaxis()
251+
ax.set_ylim(len(labels) - 0.5, -0.5)
252+
253+
ax.xaxis.set_major_formatter(PercentFormatter(1.0))
254+
255+
if title:
256+
ax.set_title(title)
257+
258+
fig.tight_layout()
259+
260+
if output:
261+
fig.savefig(output, dpi=150)
262+
else:
263+
plt.show()
271264

272265
return 0
273266

0 commit comments

Comments
 (0)