[英]Compare histograms with different x-axis values
I am having some trouble working with Python histograms. 使用Python直方图时遇到一些麻烦。 I have 2 Bell curves with the same number of points but with dramatically different values for those points.
我有2个Bell曲线,它们的点数相同,但这些点的值却大不相同。 I want to compare the shape of the curves.
我想比较曲线的形状。 Plots 1 and 2 show what I am getting.
图1和图2显示了我所得到的。 I want it to look like plot 3 below, but not with points!
我希望它看起来像下面的图3,但不带分数!
import numpy as np
import matplotlib.pyplot as plt
hist1 = np.random.normal(0,100,1000)
hist2 = np.random.normal(0,1,1000)
nBins = 100
plt.figure(1)
plt.hist((hist1,hist2),bins=nBins)
plt.figure(2)
plt.hist(hist1,bins=nBins)
plt.hist(hist2,bins=nBins)
plt.figure(3)
plt.plot(np.histogram(hist1,bins=nBins)[0],'o')
plt.plot(np.histogram(hist2,bins=nBins)[0],'o')
It was indeed pretty simple. 确实很简单。
Just had to standardize both functions before and plot them separately in the same figure. 之前只需要标准化这两个功能,然后在同一图中分别绘制它们即可。
import numpy as np
import matplotlib.pyplot as plt
hist1 = np.random.normal(0,100,1000)
hist2 = np.random.normal(0,1,1000)
nBins = 10
def Standardize(distribution):
newDistribution = (distribution-np.mean(distribution))/np.std(distribution)
return newDistribution
plt.figure(2)
plt.hist(Standardize(hist1),bins=nBins)
plt.hist(Standardize(hist2),bins=nBins)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.