【问题标题】:Dark Background Matplotlib Style with White Background on Axis轴上带有白色背景的深色背景 Matplotlib 样式
【发布时间】:2023-03-11 05:20:02
【问题描述】:
当使用style.use('dark_background') 时,我的图表的轴将保持白色背景,使轴的标签和代码不可见(白色背景上的白色字体。
如果我改用任何其他样式,标签通常会在绘图时显示出来。
我正在使用 Jupyter Notebook。
有什么想法吗?
谢谢!
【问题讨论】:
标签:
python
matplotlib
plot
jupyter-notebook
styles
【解决方案1】:
标签和轴仍然存在,它们只是黑色的,因此它们与深色背景融为一体。您应该尝试修改标签和轴的颜色,按照this answer here.
ax.spines['bottom'].set_color('#dddddd')
ax.spines['top'].set_color('#dddddd')
ax.spines['right'].set_color('red')
ax.spines['left'].set_color('red')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
ax.yaxis.label.set_color('red')
ax.xaxis.label.set_color('red')
ax.title.set_color('red')
【解决方案2】:
我无法诊断问题,但能够找到解决方案。
用所描述的问题绘制绘图后,再次导入包 matplotlib 并重新绘制绘图,这应该也将深色背景扩展到轴,并使它们可见。
这个问题似乎只有在使用 Jupyter Notebook 时才会发生。