<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">When calling plt.hist(a), with a containing a np.nan value, the error raised is:<br>
"max must be larger than min in range parameter."<br>
This is confusing especially for novice users unfamiliar with the fact that np.nan&gt;x is True for any number x.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
import numpy as np
plt.hist([1,2,3,np.nan])
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">plt</span>.<span class="pl-en">hist</span>([<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-s1">np</span>.<span class="pl-s1">nan</span>])</pre></div>
<p dir="auto"><strong>Actual outcome</strong><br>
C:\Continuum\Anaconda2\lib\site-packages\numpy\lib\function_base.pyc in histogram(a, bins, range, normed, weights, density)<br>
664     if mn &gt; mx:<br>
665         raise ValueError(<br>
--&gt; 666             'max must be larger than min in range parameter.')<br>
667     if not np.all(np.isfinite([mn, mx])):<br>
668         raise ValueError(</p>
<p dir="auto">ValueError: max must be larger than min in range parameter.```</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">ValueError: values in histogram contains nan```</p>
<p dir="auto"><strong>Matplotlib version</strong><br>
matplotlib version 1.5.3<br>
python version python 2.7 - 1.12.0 for windows 64 bit</p>
<ul dir="auto">
<li>How did you install Matplotlib and Python (pip, anaconda, from source ...)<br>
Anaconda installation</li>
</ul>
<p dir="auto">I notice that this code will plot with warnings:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from matplotlib import pyplot as plt
from numpy import NaN
plt.hist([1, NaN, 4], range=[0,5])"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">from</span> <span class="pl-s1">numpy</span> <span class="pl-k">import</span> <span class="pl-v">NaN</span>
<span class="pl-s1">plt</span>.<span class="pl-en">hist</span>([<span class="pl-c1">1</span>, <span class="pl-v">NaN</span>, <span class="pl-c1">4</span>], <span class="pl-s1">range</span><span class="pl-c1">=</span>[<span class="pl-c1">0</span>,<span class="pl-c1">5</span>])</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:229: RuntimeWarning: invalid value encountered in greater_equal
  keep = (tmp_a &gt;= mn)
/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:230: RuntimeWarning: invalid value encountered in less_equal
  keep &amp;= (tmp_a &lt;= mx)"><pre class="notranslate"><code class="notranslate">/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:229: RuntimeWarning: invalid value encountered in greater_equal
  keep = (tmp_a &gt;= mn)
/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:230: RuntimeWarning: invalid value encountered in less_equal
  keep &amp;= (tmp_a &lt;= mx)
</code></pre></div>
<p dir="auto">Whereas this code ends up with an error because of how the range is determined:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from matplotlib import pyplot as plt
from numpy import NaN
plt.hist([1, NaN, 4])"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">from</span> <span class="pl-s1">numpy</span> <span class="pl-k">import</span> <span class="pl-v">NaN</span>
<span class="pl-s1">plt</span>.<span class="pl-en">hist</span>([<span class="pl-c1">1</span>, <span class="pl-v">NaN</span>, <span class="pl-c1">4</span>])</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py&quot;, line 2958, in hist
    stacked=stacked, data=data, **kwargs)
  File &quot;/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py&quot;, line 1812, in inner
    return func(ax, *args, **kwargs)
  File &quot;/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.py&quot;, line 6010, in hist
    m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
  File &quot;/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py&quot;, line 176, in histogram
    'max must be larger than min in range parameter.')
AttributeError: max must be larger than min in range parameter."><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 2958, in hist
    stacked=stacked, data=data, **kwargs)
  File "/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 1812, in inner
    return func(ax, *args, **kwargs)
  File "/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 6010, in hist
    m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
  File "/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py", line 176, in histogram
    'max must be larger than min in range parameter.')
AttributeError: max must be larger than min in range parameter.
</code></pre></div>
<p dir="auto">If we're willing to forgive NaNs in the first case and just plot while ignoring them, wouldn't it also make sense to ignore them in the range computation?  Or if that's a bad idea, maybe we could return an error that makes it clear to the user that the problem was NaNs in the data?</p>
<p dir="auto">The friend who showed this to me was stumped by the error message because his data was huge and he had no idea it contained NaNs.  When he saw that AttributeError he just thought "But I'm letting matplotlib decide the range, how can it be wrong?"</p>