【问题标题】:Dark Background Matplotlib Style with White Background on Axis轴上带有白色背景的深色背景 Matplotlib 样式
【发布时间】:2023-03-11 05:20:02
【问题描述】:

当使用style.use('dark_background') 时,我的图表的轴将保持白色背景,使轴的标签和代码不可见(白色背景上的白色字体。

如果我改用任何其他样式,标签通常会在绘图时显示出来。

我正在使用 Jupyter Notebook。

有什么想法吗?

谢谢!

【问题讨论】:

  • dark_background 风格works fine。它会将数字着色为白色,以便它们在黑色背景上可见。如果您在使用时遇到问题,请参阅 minimal reproducible example 了解所需的内容。

标签: 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 时才会发生。

    【讨论】:

      猜你喜欢
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 2021-05-20
      • 1970-01-01
      相关资源
      最近更新 更多