- 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
- 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