python - 比较具有不同 x 轴值的直方图

标签 python matplotlib histogram

我在使用 Python 直方图时遇到一些问题。我有两条贝尔曲线,它们的点数相同,但这些点的值却截然不同。我想比较曲线的形状。图 1 和图 2 显示了我得到的结果。我希望它看起来像下面的图 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')

enter image description here

最佳答案

这确实很简单。

之前只需标准化这两个函数并将它们分别绘制在同一个图中。

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)

关于python - 比较具有不同 x 轴值的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47014504/

相关文章:

python - Matplotlib 绘图以错误的方式绘制

python - 删除 Canvas 上的点/线 Python Matplotlib

python - 如何在 matplotlib 中并排绘制堆叠直方图?

python - 在大学电脑上安装python模块

python - 来自密集张量的稀疏张量(矩阵) Tensorflow

python - 使用 pyplot 获取数据框错误日期(偏移一天)

r - 更改 R 中特定直方图箱的颜色

python - 局部直方图均衡化

python - 在 Python 中生成连续 id 的最佳方法

python - 具有不同节点集的两个 NetworkX 图之间的差异