matplotlib中未填充的条形图

Tri*_*sen 8 matplotlib bar-chart

使用直方图,有一个简单的内置选项histtype='step'.如何制作相同风格的条形图?

XVa*_*ted 8

[在阅读评论后添加答案]将可选关键字设置fill=False为条形图:

import matplotlib.pyplot as plt

plt.bar(bins[:5], counts[:5], fill=False, width=60)  # <- this is the line

plt.title("Number of nodes with output at timestep")
plt.xlabel("Node count")
plt.ylabel("Timestep (s)")
Run Code Online (Sandbox Code Playgroud)

会给: 在此输入图像描述

或者使用plt.plot关键字ls='steps':

plt.plot(bins[-100:], counts[-100:], ls='steps')
plt.title("Number of nodes with output at timestep")
plt.xlabel("Node count")
plt.ylabel("Timestep (s)")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


iso*_*eel 7

虽然 OP 链接到一个帖子,该帖子回答了一个与直方图步骤图有关的略有不同的问题,但对于经过这里的任何人来说,这是一个解决方案,他们专门试图关闭pyplot.bar条形图中的面部颜色:

import matplotlib.pyplot as plt
import numpy as np

# create x coords for the bar plot
x = np.linspace(1, 10, 10)

# cook up some random bar heights -- exact results may vary :-P
y = np.random.randn(10)
z = np.random.randn(10) * 2

# plot bars with face color off
plt.bar(x-0.2, y, width=0.4, edgecolor='purple', color='None')
plt.bar(x+0.2, z, width=0.4, edgecolor='darkorange', color='None')
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

请注意,杆边缘具有可设定的matplotlib.lines.Line2D属性,例如linewidthlinestylealpha,等等:

plt.bar(x-0.2, y, width=0.4, edgecolor='purple', color='None', 
linewidth=0.75, linestyle='--')
plt.bar(x+0.2, z, width=0.4, edgecolor='darkorange', color='None',
linewidth=1.5, linestyle='-.')
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明