[Matplotlib-users] axes.hist() with 2D input

Poughon Victor Victor.Poughon at cnes.fr
Thu Oct 6 08:36:29 EDT 2016


Working with images as 2D numpy arrays, it's very confusing to find that:


produce such different histograms. What I am expecting is the first one, which is the histogram of the image. But if I forget to flatten the array (which I don't need to do if I use numpy.histogram and then plot, adding to the confusion), the plotted histogram is strange. The number of bins is different, and so are the frequencies.

I'm not sure what the point of this message is, but I'd like to share my experience with this. I just spend a good 30 minutes trying to understand why the matplotlib histogram of my image was clearly wrong. The pyplot.hist and axes.hist documentation are not so great in explaining what is plotted with 2D input (I'm still not sure what I'm looking at), or at building an expectation that if you are working with an image, plt.hist(image) is NOT what you want.

To sum up, numpy.histogram and matplotlib's hist() have VERY different behaviors for 2D input arrays. numpy flattens, and matplotlib does... what exactly?

Any thoughts?


Victor Poughon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20161006/7f3b3542/attachment.html>

More information about the Matplotlib-users mailing list