2016-09-07 77 views
3

我想从直方图中删除垂直条轮廓,但保留直方图的“蚀刻”(如果这样做的话)。Python - 从直方图中删除垂直条线

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直方图功能?我希望我提供足够的清晰度。

+0

名称说水平的,体说是垂直的。你可能想纠正其中的一个。 – Lafexlos

+0

@Lafexlos我的歉意,这是一个漫长的早晨。 – DarthLazar

+0

您是否为直方图和背景设置了相同的颜色?如果您可以用与线条相同的颜色填充条纹,创建“轮廓”效果将非常简单。 – benten

回答

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