【问题标题】:How to change background color for scatter plot in matplotlib如何在 matplotlib 中更改散点图的背景颜色
【发布时间】:2013-08-01 09:04:46
【问题描述】:

如何更改 matplotlib 中散点图的背景颜色?

目前我有

import matplotlib.pyplot as plt
plt.scatter(X, Y, c=T, marker='o', s=(0.005*r), linewidth=0, cmap=cm.coolwarm)
plt.scatter(X_stars, Y_stars, marker='o', s=(0.00000005*r), color='white')

plt.savefig(filename, format='ps')

我希望背景是黑色的,而不是白色的。 我已经将facecoloredgecolor 更改为黑色,但没有达到预期的效果。设置 transparent=True 使其透明,以便我可以在 Photoshop 中更改背景,但它必须在 matplotlib 中工作,因为我有大量的绘图。

【问题讨论】:

  • 如果你想使用state-machine interface,你可以在调用plt.scatter之后添加plt.gca().set_axis_bgcolor('black')

标签: matplotlib scatter-plot


【解决方案1】:

编辑:正如 endolith 在 cmets axisbg 中提到的,在 matplotlib 的 2.0 版中已弃用。请改用 facecolor。

ax = fig.add_subplot(111, facecolor='black')

您可以使用 add_subplot 方法的 axisbg 参数。这是一个小例子:

import matplotlib.pyplot as plt

a = random(100)*10
b = range(100)
fig = plt.figure(1)
ax = fig.add_subplot(111, axisbg='black')
ax.scatter(a,b)
fig.canvas.draw()

【讨论】:

  • 谢谢,对我帮助很大!
  • 现在叫facecolor
猜你喜欢
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-05
  • 2014-10-04
  • 1970-01-01
相关资源
最近更新 更多