Skip to content

Instantly share code, notes, and snippets.

@SHDShim
Last active July 27, 2019 21:44
Show Gist options
  • Save SHDShim/2a5fba4c7d27c3e908988aebecd0488e to your computer and use it in GitHub Desktop.
Save SHDShim/2a5fba4c7d27c3e908988aebecd0488e to your computer and use it in GitHub Desktop.
matplotlib, dark background, python, jupyter

To make a plot for keynote dark theme

  1. Use the custom made style file below.
dark_ppt = True #False

if dark_ppt:
    with plt.style.context('~/Python/stylelib/talk-dark.mplstyle'):
        [plot_function_call]
else:
    with plt.style.context('default'):
        [plot_function_call]

The script in the file is:

# Set black background default line colors to white.

lines.color: black
patch.edgecolor: black

text.color: black
#font.family: sans-serif
#font.sans-serif: Helvetica

axes.facecolor: (1,1,0.95)
axes.edgecolor: black
axes.labelcolor: white
#axes.prop_cycle: cycler('color', ['8dd3c7', 'feffb3', 'bfbbd9', 'fa8174', '81b1d2', 'fdb462', 'b3de69', 'bc82bd', 'ccebc4', 'ffed6f'])
axes.grid: False

xtick.color: white
ytick.color: white

#grid.color: .9
#grid.linestyle: -
#grid.alpha: .5

legend.facecolor: (1,1,0.95)

figure.facecolor: black
figure.edgecolor: black

savefig.facecolor: black
savefig.edgecolor: black
  1. Alternatively, doing this directly in your code.
# set color scheme
plt.style.use('dark_background')

fig, ax = plt.subplots(figsize=(15,7))

# set background color
bg_color = (1,1,0.9)
ax.set_facecolor(bg_color)

ax.plot(spr_x, out.best_fit, 'r-', label='total fit')
ax.set_ylabel('Intensity'); ax.set_xlabel('Wavenumber')

# change legend background color
l = ax.legend(facecolor=bg_color)
# fix legend color
for text in l.get_texts():
    text.set_color("black")

plt.savefig('test.pdf', bbox_inches='tight')

After this make sure you set the mode back to default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment