Python - 从直方图中删除垂直条线

时间:2016-09-07 14:21:20

标签: python matplotlib histogram

我想从直方图中删除垂直条纹,但保留"蚀刻"直方图的结果,如果是这样的话。

import matplotlib.pyplot as plt
import numpy as np  

bins = 35

fig = plt.figure(figsize=(7,6))
ax = fig.add_subplot(111)

ax.hist(subVel_Hydro1, bins=bins, facecolor='none', 
        edgecolor='black', label = 'Pecuiliar Vel')
ax.set_xlabel('$v_{_{B|A}} $ [$km\ s^{-1}$]', fontsize = 16)
ax.set_ylabel(r'$P\ (r_{_{B|A}} )$', fontsize = 16)
ax.legend(frameon=False)

给予

enter image description here

这在matplotlibs直方图功能中是否可行?我希望我提供了足够的清晰度。

1 个答案:

答案 0 :(得分:5)

pyplot.hist()中,您可以设置histtype = 'step'的值。示例代码:

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

x = np.random.normal(0,1,size=1000)

fig = plt.figure()
ax = fig.add_subplot(111)

ax.hist(x, bins=50, histtype = 'step', fill = None)



plt.show()

示例输出:

enter image description here