如何在matplotlib中更改散点图的背景颜色 [英] How to change background color for scatter plot in matplotlib

查看:239
本文介绍了如何在matplotlib中更改散点图的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I change the background color of a scatter plot in 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')

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

I want the background to be black, not white. I already changed facecolor and edgecolor to black, but without the desired effect. Setting transparent=True made it transparent so that I could change the background in Photoshop, but it must work in matplotlib as I have a very large number of plots.

推荐答案

正如endlith在评论中提到的,axisbg在matplotlib的2.0版中已弃用.改用 facecolor.

As mentionned by endolith in the comments axisbg was deprecated in version 2.0 of matplotlib. Use facecolor instead.

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

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

You could use the axisbg argument of the add_subplot method. Here's a little example:

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

这篇关于如何在matplotlib中更改散点图的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆