how to scale the histogram plot via matplotlib

橙三吉。 提交于 2019-12-02 01:29:01

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!