<p dir="auto">Sorry if this is a duplicate...it seems like this would have come up for somebody else before, but I can't find anything about it.</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong><br>
When using AxesGrid and the 'extend' option for filled contours, the last rectangular color levels before the arrow-shaped endpoints are blank.  A workaround is to manually create the colorbar via <code class="notranslate">mpl.colorbar.ColorbarBase</code>.</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 numpy as np

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
import matplotlib as mpl

levels = np.arange(0., 1.2, 0.15)

# This yields blank values just before the end arrows in the colorbar.
fig = plt.figure()
axgrid = AxesGrid(fig, 111, 
                  nrows_ncols=(1, 1), 
                  ngrids=1,
                  cbar_mode='single')
ax = axgrid[0]
cs = ax.contourf(np.random.random((10, 20)),
                 extend='both')
cbar = axgrid.cbar_axes[0].colorbar(cs)

# This problem does not occur when not using AxesGrid.
fig, ax = plt.subplots()
cs = ax.contourf(np.random.random((10, 20)),
                 extend='both')
cbar = plt.colorbar(cs, ax=ax)

# The problem also doesn't occur if using AxesGrid + manually creating the colorbar.
fig = plt.figure()
axgrid = AxesGrid(fig, 111, 
                  nrows_ncols=(1, 1), 
                  ngrids=1,
                  cbar_mode='single')
ax = axgrid[0]
cs = ax.contourf(np.random.random((10, 20)),
                 extend='both', levels=levels)

cmap = mpl.cm.viridis
cb = mpl.colorbar.ColorbarBase(axgrid.cbar_axes[0], cmap=cmap,
                               boundaries=levels,
                               orientation='vertical', extend='both')"><pre class="notranslate"><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-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">from</span> <span class="pl-s1">mpl_toolkits</span>.<span class="pl-s1">axes_grid1</span> <span class="pl-k">import</span> <span class="pl-v">AxesGrid</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">as</span> <span class="pl-s1">mpl</span>

<span class="pl-s1">levels</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">0.</span>, <span class="pl-c1">1.2</span>, <span class="pl-c1">0.15</span>)

<span class="pl-c"># This yields blank values just before the end arrows in the colorbar.</span>
<span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>()
<span class="pl-s1">axgrid</span> <span class="pl-c1">=</span> <span class="pl-v">AxesGrid</span>(<span class="pl-s1">fig</span>, <span class="pl-c1">111</span>, 
                  <span class="pl-s1">nrows_ncols</span><span class="pl-c1">=</span>(<span class="pl-c1">1</span>, <span class="pl-c1">1</span>), 
                  <span class="pl-s1">ngrids</span><span class="pl-c1">=</span><span class="pl-c1">1</span>,
                  <span class="pl-s1">cbar_mode</span><span class="pl-c1">=</span><span class="pl-s">'single'</span>)
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">axgrid</span>[<span class="pl-c1">0</span>]
<span class="pl-s1">cs</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">contourf</span>(<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random</span>((<span class="pl-c1">10</span>, <span class="pl-c1">20</span>)),
                 <span class="pl-s1">extend</span><span class="pl-c1">=</span><span class="pl-s">'both'</span>)
<span class="pl-s1">cbar</span> <span class="pl-c1">=</span> <span class="pl-s1">axgrid</span>.<span class="pl-s1">cbar_axes</span>[<span class="pl-c1">0</span>].<span class="pl-en">colorbar</span>(<span class="pl-s1">cs</span>)

<span class="pl-c"># This problem does not occur when not using AxesGrid.</span>
<span class="pl-s1">fig</span>, <span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>()
<span class="pl-s1">cs</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">contourf</span>(<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random</span>((<span class="pl-c1">10</span>, <span class="pl-c1">20</span>)),
                 <span class="pl-s1">extend</span><span class="pl-c1">=</span><span class="pl-s">'both'</span>)
<span class="pl-s1">cbar</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">cs</span>, <span class="pl-s1">ax</span><span class="pl-c1">=</span><span class="pl-s1">ax</span>)

<span class="pl-c"># The problem also doesn't occur if using AxesGrid + manually creating the colorbar.</span>
<span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>()
<span class="pl-s1">axgrid</span> <span class="pl-c1">=</span> <span class="pl-v">AxesGrid</span>(<span class="pl-s1">fig</span>, <span class="pl-c1">111</span>, 
                  <span class="pl-s1">nrows_ncols</span><span class="pl-c1">=</span>(<span class="pl-c1">1</span>, <span class="pl-c1">1</span>), 
                  <span class="pl-s1">ngrids</span><span class="pl-c1">=</span><span class="pl-c1">1</span>,
                  <span class="pl-s1">cbar_mode</span><span class="pl-c1">=</span><span class="pl-s">'single'</span>)
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">axgrid</span>[<span class="pl-c1">0</span>]
<span class="pl-s1">cs</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">contourf</span>(<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random</span>((<span class="pl-c1">10</span>, <span class="pl-c1">20</span>)),
                 <span class="pl-s1">extend</span><span class="pl-c1">=</span><span class="pl-s">'both'</span>, <span class="pl-s1">levels</span><span class="pl-c1">=</span><span class="pl-s1">levels</span>)

<span class="pl-s1">cmap</span> <span class="pl-c1">=</span> <span class="pl-s1">mpl</span>.<span class="pl-s1">cm</span>.<span class="pl-s1">viridis</span>
<span class="pl-s1">cb</span> <span class="pl-c1">=</span> <span class="pl-s1">mpl</span>.<span class="pl-s1">colorbar</span>.<span class="pl-v">ColorbarBase</span>(<span class="pl-s1">axgrid</span>.<span class="pl-s1">cbar_axes</span>[<span class="pl-c1">0</span>], <span class="pl-s1">cmap</span><span class="pl-c1">=</span><span class="pl-s1">cmap</span>,
                               <span class="pl-s1">boundaries</span><span class="pl-c1">=</span><span class="pl-s1">levels</span>,
                               <span class="pl-s1">orientation</span><span class="pl-c1">=</span><span class="pl-s">'vertical'</span>, <span class="pl-s1">extend</span><span class="pl-c1">=</span><span class="pl-s">'both'</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/6200806/32759626-3b36ad88-c8e2-11e7-89b7-2dfe12b86ae7.png"><img width="432" alt="bug" src="https://user-images.githubusercontent.com/6200806/32759626-3b36ad88-c8e2-11e7-89b7-2dfe12b86ae7.png" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/6200806/32759627-3b6412fa-c8e2-11e7-9190-49a1ecf35bfe.png"><img width="432" alt="no_bug" src="https://user-images.githubusercontent.com/6200806/32759627-3b6412fa-c8e2-11e7-9190-49a1ecf35bfe.png" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/6200806/32759628-3b814aaa-c8e2-11e7-8351-306cdb6fafe1.png"><img width="432" alt="workaround" src="https://user-images.githubusercontent.com/6200806/32759628-3b814aaa-c8e2-11e7-8351-306cdb6fafe1.png" style="max-width: 100%;"></a></p>
<p dir="auto">See the attached images.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: MacOS + Jupyter Notebook</li>
<li>Matplotlib version: 2.1.0</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): MacOSX</li>
<li>Python version: 3.6</li>
<li>Jupyter version (if applicable): 4.3.0</li>
<li>Other libraries:</li>
</ul>
<p dir="auto">Matplotlib installed via <code class="notranslate">conda install -c conda-forge matplotlib</code></p>
<p dir="auto">When trying to plot a 2d DataArray and setting the extent of one of the two axis with a numpy datetime64 value, the following error is returned:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''"><pre class="notranslate"><code class="notranslate">TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
</code></pre></div>
<p dir="auto">I suggest adding the following code after this line </p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/matplotlib/matplotlib/blob/ca4958b8d755c303cfd0617556530da08094bab5/lib/matplotlib/image.py#L972">matplotlib/lib/matplotlib/image.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 972
      in
      <a data-pjax="true" class="commit-tease-sha" href="/matplotlib/matplotlib/commit/ca4958b8d755c303cfd0617556530da08094bab5">ca4958b</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L972" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="972"></td>
          <td id="LC972" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-s1">self</span>.<span class="pl-s1">_extent</span> <span class="pl-c1">=</span> <span class="pl-s1">xmin</span>, <span class="pl-s1">xmax</span>, <span class="pl-s1">ymin</span>, <span class="pl-s1">ymax</span> <span class="pl-c1">=</span> <span class="pl-s1">extent</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
 :<p></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from matplotlib.dates import date2num
extent_ = []
for value in extent:
    if np.issubdtype(value.dtype, np.datetime64):
        value = date2num(value)

    extent_.append(value)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">dates</span> <span class="pl-k">import</span> <span class="pl-s1">date2num</span>
<span class="pl-s1">extent_</span> <span class="pl-c1">=</span> []
<span class="pl-k">for</span> <span class="pl-s1">value</span> <span class="pl-c1">in</span> <span class="pl-s1">extent</span>:
    <span class="pl-k">if</span> <span class="pl-s1">np</span>.<span class="pl-en">issubdtype</span>(<span class="pl-s1">value</span>.<span class="pl-s1">dtype</span>, <span class="pl-s1">np</span>.<span class="pl-s1">datetime64</span>):
        <span class="pl-s1">value</span> <span class="pl-c1">=</span> <span class="pl-en">date2num</span>(<span class="pl-s1">value</span>)

    <span class="pl-s1">extent_</span>.<span class="pl-en">append</span>(<span class="pl-s1">value</span>)</pre></div>
<p dir="auto">This is linked to an issue I started on xarray:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1244977848" data-permission-text="Title is private" data-url="https://github.com/pydata/xarray/issues/6629" data-hovercard-type="issue" data-hovercard-url="/pydata/xarray/issues/6629/hovercard" href="https://github.com/pydata/xarray/issues/6629">pydata/xarray#6629</a></p>