Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib - Stepped histogram with already binned data

I am trying to get a histogram with already binned data. I have been trying to use bar() for this, but I can't seem to figure out how to make it a stepped histogram like this one from the examples, instead of a filled histogram.

enter image description here

like image 913
madtowneast Avatar asked Jul 02 '12 15:07

madtowneast


People also ask

How do you plot a normalized histogram in Python?

To normalize a histogram in Python, we can use hist() method. In normalized bar, the area underneath the plot should be 1.

What does bins mean in histogram Matplotlib?

The towers or bars of a histogram are called bins. The height of each bin shows how many values from that data fall into that range. Width of each bin is = (max value of data – min value of data) / total number of bins. The default value of the number of bins to be created in a histogram is 10.


1 Answers

You could cheat, by offsetting your data and using plot instead:

from matplotlib import pyplot
import numpy as np

#sample data:
x = np.arange(30)
y = np.cumsum(np.arange(30))
#offset the x for horizontal, repeat the y for vertical:
x = np.ravel(zip(x,x+1))
y = np.ravel(zip(y,y))

pyplot.plot(x,y)
pyplot.savefig('plt.png')

the plot:

enter image description here

like image 136
fraxel Avatar answered Oct 03 '22 18:10

fraxel