Incomplete bar in matplotlib

With histograms, there is a simple built-in option histtype='step'. How to create a tablet in the same style?

+5
source share
2 answers

[adding response after reading comments] Set for optional keyword fill=Falsefor graphs:

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)")

will give: enter image description here

Or use plt.plotwith keyword 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)")

enter image description here

+6
source

Despite the fact that OP is related to the message that answered a slightly different question regarding the histogram step graphs, here is a solution for any user passing here who specifically tries to turn off the complexion in pyplot.barbar graphs:

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

enter image description here

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

enter image description here

+1

All Articles