【问题标题】:Python - Removing vertical bar lines from histogramPython - 从直方图中删除垂直条线
【发布时间】:2016-09-07 14:21:19
【问题描述】:

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

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)

给予

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

【问题讨论】:

  • 标题表示水平,正文表示垂直。您可能需要更正其中一个。
  • @Lafexlos 很抱歉,让我们度过了漫长的早晨。
  • 您是否设置直方图和背景的颜色相同?如果您可以将条形填充为与线条相同的颜色,则创建“剪影”效果会很容易。

标签: python matplotlib histogram


【解决方案1】:

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

样本输出:

【讨论】:

    猜你喜欢
    • 2021-10-25
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 2012-08-01
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 2019-05-26
    相关资源
    最近更新 更多