[Matplotlib-users] axes.hist() with 2D input
pmhobson at gmail.com
Thu Oct 6 16:48:29 EDT 2016
pyplot.hist(x) where x is a N (rows) x M (cols) array will generate M
histograms and plot on a single Axes object.
Consider an array that likely has far fewer columns than your image:
from matplotlib import pyplot
data = numpy.random.normal(size=(37, 4))
fig, ax = pyplot.subplots()
Does that make sense?
On Thu, Oct 6, 2016 at 5:36 AM, Poughon Victor <Victor.Poughon at cnes.fr>
> 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
> Any thoughts?
> Victor Poughon
> Matplotlib-users mailing list
> Matplotlib-users at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Matplotlib-users