<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Ohhhhhh I see now. I was so confused because the histogram with my 2D (non flatten()'ed) input looks like this:<br>
<a href="http://i.imgur.com/NswA4El.png" target="_blank">http://i.imgur.com/NswA4El.png</a><br>
<br>
but that's just because there are a lot of columns (3500 in that case), and matplotlib with render the histogram bars *side-by-side* for each bin.<br>
<br>
Looking at the figure above, I thought that somehow the bins edges were not the same for each column, or that there were thousands of bins, or something like that, but it's just because it's putting 3500 vertical bars in each bin? So there are still 10 bins,
 but with a lot of vertical bars in each. For reference here is the same histogram with flatten()'ed input:
<a href="http://i.imgur.com/x0dwUoL.png" target="_blank">http://i.imgur.com/x0dwUoL.png</a>. Thank you your example code helped me get that.<br>
<br>
I think the documentation for pyplot.hist and axes.hist could be improved regarding this issue. Should I have a go at it in a PR?<br>
<br>
Thanks a lot,<br>
(matplotlib is awesome)<br>
<div><br>
<div style="font-family:Tahoma; font-size:13px">Victor Poughon<br>
</div>
</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF130267"><font face="Tahoma" color="#000000" size="2"><b>De :</b> Paul Hobson [pmhobson@gmail.com]<br>
<b>Envoyé :</b> jeudi 6 octobre 2016 22:48<br>
<b>À :</b> Poughon Victor<br>
<b>Cc :</b> matplotlib-users@python.org<br>
<b>Objet :</b> Re: [Matplotlib-users] axes.hist() with 2D input<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">pyplot.hist(x) where x is a N (rows) x M (cols) array will generate M histograms and plot on a single Axes object.
<div><br>
</div>
<div>Consider an array that likely has far fewer columns than your image:</div>
<div><br>
</div>
<div>
<div>import numpy</div>
<div>from matplotlib import pyplot</div>
<div><br>
</div>
<div>data = numpy.random.normal(size=(37, 4))</div>
<div>fig, ax = pyplot.subplots()</div>
<div>ax.hist(data)</div>
</div>
<div><br>
</div>
<div>Does that make sense?</div>
<div>-p</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Oct 6, 2016 at 5:36 AM, Poughon Victor <span dir="ltr">
<<a href="mailto:Victor.Poughon@cnes.fr" target="_blank">Victor.Poughon@cnes.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">Hi,<br>
<br>
Working with images as 2D numpy arrays, it's very confusing to find that:<br>
<br>
plt.hist(image.flatten())<br>
plt.hist(image)<br>
<br>
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.<br>
<br>
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.<br>
<br>
To sum up, numpy.histogram and matplotlib's hist() have VERY different behaviors for 2D input arrays. numpy flattens, and matplotlib does... what exactly?<br>
<br>
Any thoughts?<br>
<br>
cheers,<br>
<div><br>
<div style="font-family:Tahoma; font-size:13px">Victor Poughon<br>
</div>
</div>
</div>
</div>
<br>
______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org" target="_blank">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/matplotlib-<wbr>users</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>