如何通过Matplotlib扩展直方图绘图

3
您可以看到下面有一个直方图。
它是这样创建的:pl.hist(data1,bins=20,color='green',histtype="step",cumulative=-1)
如何缩放直方图?
例如,让直方图的高度只有现在的三分之一。
此外,是否有方法可以删除左侧的垂直线? enter image description here
1个回答

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()

hist_neg_cumulative是正在绘制的数据数组。因此,您可以在将其传递给绘图函数之前根据需要重新调整它。这也不会绘制垂直线。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接