gpt4 book ai didi

python - 绘制阶梯直方图而不用底线闭合多边形

转载 作者:行者123 更新时间:2023-11-28 17:46:52 25 4
gpt4 key购买 nike

如何删除关闭阶梯直方图路径的底线?

enter image description here

enter image description here

import numpy as np
import matplotlib.pyplot as plt

mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_subplot(111)
n, bins, patches = ax.hist(x, 50, normed=1, histtype='step')
plt.ylim(-.005, plt.ylim()[1])
plt.show()

更新:已报告并已修复:

https://github.com/matplotlib/matplotlib/pull/2113

最佳答案

最简单的方法是自己绘制:

import numpy as np
import matplotlib.pyplot as plt

mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_subplot(111)
bins, edges = np.histogram(x, 50, normed=1)
ax.step(edges[:-1], bins, where='post')
plt.ylim(-.005, plt.ylim()[1])
plt.show()

参见 docStep function in matplotlib理解where=post。您需要切掉边缘的最后一个条目,因为直方图返回 [left_edege_0, left_edge_1, ..., left_edge_(n-1), right_edge_(n-1)](请参阅 doc )

这已被视为回归,并将至少在 1.3 中得到修复。相关公关:https://github.com/matplotlib/matplotlib/pull/2113

关于python - 绘制阶梯直方图而不用底线闭合多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16862501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com