问题描述
您可以看到下面的直方图.
它像pl.hist(data1,bins=20,color='green',histtype="step",cumulative=-1)
如何缩放直方图?
例如,让直方图的高度变成现在的三分之一.
You can see there is histogram below.
It is made likepl.hist(data1,bins=20,color='green',histtype="step",cumulative=-1)
How to scale the histogram?
For example, let the height of the histogram be one third of it is like now.
此外,这是一种删除左侧垂直线的方法吗?
Besides, it is a way to remove the vertical line at the left?
推荐答案
matplotlib hist
实际上只是对其他一些函数的调用.直接使用这些命令通常更容易,使您可以检查数据并直接对其进行修改:
The matplotlib hist
is actually just making calls to some other functions. It is often easier to use these directly allowing you to inspect the data and modify it directly:
# 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是要绘制的数据数组.因此,您可以根据需要调整比例,然后再将其传递给绘图功能.这也不会绘制垂直线.
The hist_neg_cumulative is the array of data being plotted. So you can rescale is as you wish before passing it to the plotting function. This also doesn't plot the vertical line.
这篇关于如何通过matplotlib缩放直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!