简体   繁体   English

一轴上的3个直方图-Matplotlib Python

[英]3 Histograms on one axis - Matplotlib python

I am trying to create a graph that has 3 histograms on one axis. 我正在尝试创建一个在一个轴上具有3个直方图的图形。 I want them to overlap each with a different color. 我希望它们以不同的颜色重叠。 The insides are semi-transparent. 内部是半透明的。

Whenever I use multiple colors like RGB with alpha 0.5, the colors overlap and create a nasty color. 每当我使用多种颜色(如带有alpha 0.5的RGB)时,这些颜色就会重叠并产生令人讨厌的颜色。

How would I portray the 3 graphs without producing a nasty color? 在不产生令人讨厌的颜色的情况下,我该如何描绘这三个图表? I still want the graphs to overlap in the same nature, just in a way that is aesthetically pleasing. 我仍然希望这些图以相同的性质重叠,只是在美学上令人愉悦。 I have seen graphs that overlap, but you can still see each histograms color distinctly. 我已经看到了重叠的图形,但是您仍然可以看到每个直方图的颜色明显不同。 Thanks 谢谢

You may use the colors from what you call "good graph" as follows: 您可以按以下方式使用所谓的“好图”中的颜色:

import matplotlib.pyplot as plt
import numpy as np; np.random.seed(42)

x1 = np.random.rand(15)*3
x2 = np.random.rayleigh(size=15)
x3 = np.random.binomial(3,0.7,size=15)

bins= np.linspace(0,4,11)
kw = dict(bins=bins, histtype='step', fill=True)
plt.hist(x1, fc=(.14,.57,.14,.4), ec=(.14,.57,.14, 1), **kw)
plt.hist(x2, fc=(.16,.16,1.0,.4), ec=(.16,.16,1.0, 1), **kw)
plt.hist(x3, fc=(1.0,.14,.14,.4), ec=(1.0,.14,.14, 1), **kw)

plt.show()

在此处输入图片说明

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

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