如何通过matplotlib缩放直方图

que*_*ang 2 python matplotlib histogram

你可以看到下面有直方图.
它像是 pl.hist(data1,bins=20,color='green',histtype="step",cumulative=-1)
如何缩放直方图?
例如,让直方图的高度为现在的三分之一.

此外,它是一种删除左侧垂直线的方法吗?

在此输入图像描述

Gre*_*reg 7

matplotlib hist实际上只是调用其他一些函数.直接使用它们通常更容易,允许您检查数据并直接修改它:

# Generate some data
data = np.random.normal(size=1000)

# Generate the histogram data directly
hist, bin_edges = np.histogram(data, bins=10)

# Get the reversed cumulative sum
hist_neg_cumulative = [np.sum(hist[i:]) for i in range(len(hist))]

# Get the cin centres rather than the edges
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2.

# Plot
plt.step(bin_centers, hist_neg_cumulative)

plt.show()
Run Code Online (Sandbox Code Playgroud)

hist_neg_cumulative是绘制的数据数组.因此,在将其传递给绘图功能之前,您可以按照自己的意愿重新缩放.这也不绘制垂直线.