相关疑难解决方法(0)

使用matplotlib同时绘制两个直方图

我使用文件中的数据创建了直方图,没有问题.现在我想在同一个直方图中叠加来自另一个文件的数据,所以我做了类似的事情

n,bins,patchs = ax.hist(mydata1,100)
n,bins,patchs = ax.hist(mydata2,100)
Run Code Online (Sandbox Code Playgroud)

但问题是,对于每个区间,只显示具有最高值的条,而另一个区间是隐藏的.我想知道如何用不同的颜色同时绘制两个直方图.

python plot matplotlib histogram

202
推荐指数
8
解决办法
27万
查看次数

Making grouped histograms bigger in Python

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 …

python numpy histogram pandas

0
推荐指数
1
解决办法
3403
查看次数

标签 统计

histogram ×2

python ×2

matplotlib ×1

numpy ×1

pandas ×1

plot ×1