4

如何删除关闭步进直方图路径的底线?

在此处输入图像描述

在此处输入图像描述

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

4

1 回答 1

2

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

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

请参阅matplotlib中的doc或Step 函数以了解. 您需要从边缘切掉最后一个条目,因为直方图返回 (请参阅 docwhere=post[left_edege_0, left_edge_1, ..., left_edge_(n-1), right_edge_(n-1)]

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

于 2013-05-31T18:04:40.800 回答