【问题标题】:Adding white breaks to bars in pyplot histogram向 pyplot 直方图中的条形添加白色中断
【发布时间】:2017-09-12 17:50:08
【问题描述】:

我想在 matplotlib 中的直方图的条形图中添加白色“中断”,因此网格线似乎会继续贯穿整个绘图,而不会干扰或在后台忙碌。我想看起来像下面这样:

我想要什么 - https://imgur.com/IUr3tz6

这是一个可以使用的测试直方图:

vals = np.random.randn(1000)
f = plt.figure(figsize=[4,4])
ax = f.add_subplot(111)
ax.hist(vals, bins=20, normed=True)

【问题讨论】:

  • 看来你想add grid lines
  • @inspectorG4dget 不过,我不想要完整的网格线 - 我只想要网格线所在的直方图条中的小视觉中断。我发现完整的背景网格在视觉上太忙了。

标签: python matplotlib


【解决方案1】:

如果你让网格线与背景颜色相同,并独立管理水平和垂直,那么你可以获得你想要的“视觉中断”。

import numpy as np
from matplotlib import pyplot as plt
vals = np.random.randn(1000)
f = plt.figure(figsize=\[4,4\])
ax = f.add_subplot(111)
ax.hist(vals, bins=20, normed=True, 
        )
ax.yaxis.grid(which="major", color='white', linestyle='-', linewidth=0.5)
ax.xaxis.grid(which="major", color='white', linestyle='-', linewidth=4)

plt.show()]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-26
    • 1970-01-01
    • 2020-01-01
    相关资源
    最近更新 更多