我使用文件中的数据创建了直方图,没有问题.现在我想在同一个直方图中叠加来自另一个文件的数据,所以我做了类似的事情
n,bins,patchs = ax.hist(mydata1,100)
n,bins,patchs = ax.hist(mydata2,100)
Run Code Online (Sandbox Code Playgroud)
但问题是,对于每个区间,只显示具有最高值的条,而另一个区间是隐藏的.我想知道如何用不同的颜色同时绘制两个直方图.
I am drawing some grouped histograms in python as per this question, but am trying to plot more histograms and make them bigger.
To give an example:
from pandas import DataFrame
import numpy as np
x = ['A']*300 + ['B']*400 + ['C']*300 + ['D']*400 + ['E']*200 + ['F']*500 +
['G']*400 + ['H']*500 + ['I']*300
y = np.random.randn(3300)
df = DataFrame({'Letter':x, 'N':y})
grouped = df.groupby('Letter')
Run Code Online (Sandbox Code Playgroud)
I then plot like this in Jupyter:
%matplotlib inline
df['N'].hist(by=df['Letter'])
Run Code Online (Sandbox Code Playgroud)
but the plots come out …