title: How to ignore NaN in colorbar?
body: <p>I have a 3d surface, accompanied by a color bar, being generated by </p>
  
  <pre><code>surf = ax.plot_surface(xv, yv, zv, ...)
  cb = fig.colorbar(surf)
  </code></pre>
  
  <p>When it works, it looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Ylo0l.png" alt="enter image description here"></p>
  
  <p>The problem is that some of the values may be NaN, in which case the colorbar fails to generate, like this:</p>
  
  <p><img src="https://i.stack.imgur.com/i323n.png" alt="Example"></p>
  
  <pre><code>C:\Users\Sam\Anaconda\lib\site-packages\matplotlib\colorbar.py:581: RuntimeWarning: invalid value encountered in greater
    inrange = (ticks &gt; -0.001) &amp; (ticks &lt; 1.001)
  C:\Users\Sam\Anaconda\lib\site-packages\matplotlib\colorbar.py:581: RuntimeWarning: invalid value encountered in less
    inrange = (ticks &gt; -0.001) &amp; (ticks &lt; 1.001)
  C:\Users\Sam\Anaconda\lib\site-packages\matplotlib\colors.py:576: RuntimeWarning: invalid value encountered in less
    cbook._putmask(xa, xa &lt; 0.0, -1)
  </code></pre>
  
  <p>I could try to replace the NaN values of zv with 0 (<code>zv[isnan(zv)] = 0</code>), but then the resulting graph has vertical cliffs, which are confusing and obscure some of the features, and it skews the color bar.</p>
  
  <p><img src="https://i.stack.imgur.com/yPC8D.png" alt="enter image description here"></p>
  
  <p>What I want is a way for the color bar to ignore NaN values. To do this I could manually set the color bar (to <code>amin(zv[~isnan(zv)])</code> and <code>amax(zv[~isnan(zv)])</code>) after it is created, but I don't know how to do this.</p>
  
  <p>Any suggestions on how to ignore NaNs when computing the colorbar and when coloring a 3d surface?</p>