虽然 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()
请注意,条形边缘具有可设置的matplotlib.lines.Line2D 属性,例如linewidth、linestyle、alpha 等:
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()