<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">For people who use numpy.datetime64() arrays with pcolormesh, a DeprecationWarning has been appearing prompting users to specify a shading kwarg 'nearest', 'auto' or 'gouraud' since shading='flat' is being deprecated. However, passing 'nearest' results in a UFuncTypeError when using 'nearest' due to a casting issue in _axes.py from _interp_grid()</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

times = np.arange(np.datetime64('2020-12-01'), np.datetime64('2020-12-31'))
yaxis = np.arange(0, 20)
caxis = np.random.normal(0.0, 1.0, (times.shape[0], yaxis.shape[0]))

plt.pcolormesh(times, yaxis, caxis.T, shading='nearest')
plt.show()"><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-s1">times</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-s1">np</span>.<span class="pl-en">datetime64</span>(<span class="pl-s">'2020-12-01'</span>), <span class="pl-s1">np</span>.<span class="pl-en">datetime64</span>(<span class="pl-s">'2020-12-31'</span>))
<span class="pl-s1">yaxis</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">20</span>)
<span class="pl-s1">caxis</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">normal</span>(<span class="pl-c1">0.0</span>, <span class="pl-c1">1.0</span>, (<span class="pl-s1">times</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>], <span class="pl-s1">yaxis</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>]))

<span class="pl-s1">plt</span>.<span class="pl-en">pcolormesh</span>(<span class="pl-s1">times</span>, <span class="pl-s1">yaxis</span>, <span class="pl-s1">caxis</span>.<span class="pl-v">T</span>, <span class="pl-s1">shading</span><span class="pl-c1">=</span><span class="pl-s">'nearest'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):

  File &quot;..\test.py&quot;, line 15, in &lt;module&gt;
    plt.pcolormesh(times, yaxis, caxis.T, shading='nearest')

  File &quot;C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\pyplot.py&quot;, line 2801, in pcolormesh
    __ret = gca().pcolormesh(

  File &quot;C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\__init__.py&quot;, line 1438, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)

  File &quot;C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\axes\_axes.py&quot;, line 6093, in pcolormesh
    X, Y, C, shading = self._pcolorargs('pcolormesh', *args,

  File &quot;C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\axes\_axes.py&quot;, line 5651, in _pcolorargs
    X = _interp_grid(X)

  File &quot;C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\axes\_axes.py&quot;, line 5633, in _interp_grid
    if not (np.all(dX &gt;= 0) or np.all(dX &lt;= 0)):

UFuncTypeError: Cannot cast ufunc 'greater_equal' input 0 from dtype('&lt;m8[D]') to dtype('&lt;m8') with casting rule 'same_kind'"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):

  File "..\test.py", line 15, in &lt;module&gt;
    plt.pcolormesh(times, yaxis, caxis.T, shading='nearest')

  File "C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 2801, in pcolormesh
    __ret = gca().pcolormesh(

  File "C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\__init__.py", line 1438, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)

  File "C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 6093, in pcolormesh
    X, Y, C, shading = self._pcolorargs('pcolormesh', *args,

  File "C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 5651, in _pcolorargs
    X = _interp_grid(X)

  File "C:\Users\iarey\anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 5633, in _interp_grid
    if not (np.all(dX &gt;= 0) or np.all(dX &lt;= 0)):

UFuncTypeError: Cannot cast ufunc 'greater_equal' input 0 from dtype('&lt;m8[D]') to dtype('&lt;m8') with casting rule 'same_kind'
</code></pre></div>
<p dir="auto"><strong>Expected outcome</strong><br>
A pcolormesh timeseries plot with random data and a np.datetime64() x-axis.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: Windows 10</li>
<li>Matplotlib version: 3.3.2 via standard conda</li>
<li>Matplotlib backend: Qt5Agg</li>
<li>Python version: 3.8.5</li>
<li>Jupyter version (if applicable):</li>
<li>Other libraries: numpy-1.19.2</li>
</ul>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">When using a datetime x-axis in a pcolormesh, and nearest shading,</p>
<blockquote>
<p dir="auto">TypeError: '&gt;=' not supported between instances of 'datetime.timedelta' and 'int'</p>
</blockquote>
<p dir="auto">is raised.</p>
<p dir="auto">From what I can tell, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="691462784" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/18398" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/18398/hovercard" href="https://github.com/matplotlib/matplotlib/pull/18398">#18398</a> assumed comparison with 0 would always be possible, but this isn't the case for <code class="notranslate">datetime.timedelta</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="from datetime import datetime

from matplotlib import pyplot as plt

x_coords = [datetime.fromtimestamp(x * 3600) for x in range(24)]
y_coords = [*range(0, 10)]
plt.pcolormesh(x_coords,
               y_coords, [[*range(24)] for _ in range(10)],
               shading=&quot;nearest&quot;)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">datetime</span> <span class="pl-k">import</span> <span class="pl-s1">datetime</span>

<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-s1">x_coords</span> <span class="pl-c1">=</span> [<span class="pl-s1">datetime</span>.<span class="pl-en">fromtimestamp</span>(<span class="pl-s1">x</span> <span class="pl-c1">*</span> <span class="pl-c1">3600</span>) <span class="pl-k">for</span> <span class="pl-s1">x</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">24</span>)]
<span class="pl-s1">y_coords</span> <span class="pl-c1">=</span> [<span class="pl-c1">*</span><span class="pl-en">range</span>(<span class="pl-c1">0</span>, <span class="pl-c1">10</span>)]
<span class="pl-s1">plt</span>.<span class="pl-en">pcolormesh</span>(<span class="pl-s1">x_coords</span>,
               <span class="pl-s1">y_coords</span>, [[<span class="pl-c1">*</span><span class="pl-en">range</span>(<span class="pl-c1">24</span>)] <span class="pl-k">for</span> <span class="pl-s1">_</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">10</span>)],
               <span class="pl-s1">shading</span><span class="pl-c1">=</span><span class="pl-s">"nearest"</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<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;.local/lib/python3.8/site-packages/matplotlib/pyplot.py&quot;, line 2801, in pcolormesh
    __ret = gca().pcolormesh(
  File &quot;.local/lib/python3.8/site-packages/matplotlib/__init__.py&quot;, line 1438, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File &quot;.local/lib/python3.8/site-packages/matplotlib/axes/_axes.py&quot;, line 6093, in pcolormesh
    X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
  File &quot;.local/lib/python3.8/site-packages/matplotlib/axes/_axes.py&quot;, line 5651, in _pcolorargs
    X = _interp_grid(X)
  File &quot;.local/lib/python3.8/site-packages/matplotlib/axes/_axes.py&quot;, line 5633, in _interp_grid
    if not (np.all(dX &gt;= 0) or np.all(dX &lt;= 0)):
TypeError: '&gt;=' not supported between instances of 'datetime.timedelta' and 'int'"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File ".local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2801, in pcolormesh
    __ret = gca().pcolormesh(
  File ".local/lib/python3.8/site-packages/matplotlib/__init__.py", line 1438, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File ".local/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 6093, in pcolormesh
    X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
  File ".local/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 5651, in _pcolorargs
    X = _interp_grid(X)
  File ".local/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 5633, in _interp_grid
    if not (np.all(dX &gt;= 0) or np.all(dX &lt;= 0)):
TypeError: '&gt;=' not supported between instances of 'datetime.timedelta' and 'int'
</code></pre></div>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">None</p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Matplotlib version: 3.3.2</li>
<li>Python version: 3.8</li>
</ul>
<p dir="auto">works with <code class="notranslate">pip3 install matplotlib==3.3.1</code>, fails with <code class="notranslate">pip3 install matplotlib==3.3.2</code></p>