首页 > 解决方案 > matplotlib 内置样式全部显示白色背景

问题描述

全部。通常是 python 和编程的新手,并且遇到了 matplotlib 的内置样式的问题。即,无论我选择哪种样式,图形背景总是显示为白色。这是我尝试过的代码:

import matplotlib.pyplot as plt

input_values = list(range(1,6))
squares = [i**2 for i in range(1,6)]

plt.style.use('seaborn')

fig, ax = plt.subplots()
ax.plot(input_values, squares, linewidth=3)

ax.set_title("Square Numbers", fontsize=24)
ax.set_xlabel("Value", fontsize=14)
ax.set_ylabel("Square of Values", fontsize=14)

ax.tick_params(axis="both", labelsize=14)

plt.show()

这就是我收到的:graph

当显示器第一次出现时,我可以短暂地看到正确样式的背景,但在一秒钟内它会变成白色。

我使用 Anaconda (python v. 3.8.3) 并尝试从 Sublime Text 3 和终端 (Git Bash) 运行,如果这值得的话。

编辑:在我的手机上打开图像确实显示了正确的样式,但无论出于何种原因,在我的计算机上打开图像时它都没有出现。

标签: pythonpython-3.xmatplotlibanaconda

解决方案


事实证明,这只是我的显示器显示设置的问题,调整亮度和对比度可以解决问题!


推荐阅读