Skip to content
Advertisement

Histogram Matplotlib

So I have a little problem. I have a data set in scipy that is already in the histogram format, so I have the center of the bins and the number of events per bin. How can I now plot is as a histogram. I tried just doing

JavaScript

but it didn’t like that. Any recommendations?

Advertisement

Answer

JavaScript

enter image description here

The object-oriented interface is also straightforward:

JavaScript

If you are using custom (non-constant) bins, you can pass compute the widths using np.diff, pass the widths to ax.bar and use ax.set_xticks to label the bin edges:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement