繁体   English   中英

绘制后更改直方图的颜色

[英]Change color of histogram after it was plotted

绘制后如何改变直方图的颜色? (使用历史记录)

z = hist([1,2,3])
z.set_color(???) < -- Something like this

还有我怎么检查直方图是什么颜色

z = hist([1,2,3])
color = z.get_color(???) < -- also Something like this

谢谢。

存在这样的功能。 您只需要存储hist返回的patches并访问每个patchesfacecolor

import matplotlib.pyplot as plt
n, bins, patches = plt.hist([1,2,3])
for p in patches:
    print p.get_facecolor()
    p.set_facecolor((1.0, 0.0, 0.0, 1.0))

输出:

(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)
(0.0, 0.5, 0.0, 1.0)

请注意,每个仓位只有一个补丁。 默认情况下, hist绘制10个bin。 您可能想使用plt.hist([1,2,3], bins=3)不同的定义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM