<h3 dir="auto">Bug summary</h3>
<p dir="auto">The color bar is not properly displayed after version 3.5.0</p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Compare:
https://matplotlib.org/stable/tutorials/colors/colormapnorms.html#twoslopenorm-different-mapping-on-either-side-of-a-center
OR
https://matplotlib.org/devdocs/tutorials/colors/colormapnorms.html#twoslopenorm-different-mapping-on-either-side-of-a-center
with the older version:
https://matplotlib.org/3.4.3/tutorials/colors/colormapnorms.html#twoslopenorm-different-mapping-on-either-side-of-a-center"><pre class="notranslate"><span class="pl-v">Compare</span>:
<span class="pl-s1">https</span>:<span class="pl-c1">//</span><span class="pl-s1">matplotlib</span>.<span class="pl-s1">org</span><span class="pl-c1">/</span><span class="pl-s1">stable</span><span class="pl-c1">/</span><span class="pl-s1">tutorials</span><span class="pl-c1">/</span><span class="pl-s1">colors</span><span class="pl-c1">/</span><span class="pl-s1">colormapnorms</span>.<span class="pl-s1">html</span><span class="pl-c">#twoslopenorm-different-mapping-on-either-side-of-a-center</span>
<span class="pl-v">OR</span>
<span class="pl-s1">https</span>:<span class="pl-c1">//</span><span class="pl-s1">matplotlib</span>.<span class="pl-s1">org</span><span class="pl-c1">/</span><span class="pl-s1">devdocs</span><span class="pl-c1">/</span><span class="pl-s1">tutorials</span><span class="pl-c1">/</span><span class="pl-s1">colors</span><span class="pl-c1">/</span><span class="pl-s1">colormapnorms</span>.<span class="pl-s1">html</span><span class="pl-c">#twoslopenorm-different-mapping-on-either-side-of-a-center</span>
<span class="pl-k">with</span> <span class="pl-s1">the</span> <span class="pl-s1">older</span> <span class="pl-s1">version</span>:
<span class="pl-s1">https</span>:<span class="pl-c1">//</span><span class="pl-s1">matplotlib</span>.<span class="pl-s1">org</span><span class="pl-c1">/</span><span class="pl-c1">3.4</span>.<span class="pl-c1">3</span><span class="pl-c1">/</span><span class="pl-s1">tutorials</span><span class="pl-c1">/</span><span class="pl-s1">colors</span><span class="pl-c1">/</span><span class="pl-s1">colormapnorms</span>.<span class="pl-s1">html</span><span class="pl-c">#twoslopenorm-different-mapping-on-either-side-of-a-center</span></pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto"><a href="https://github.com/matplotlib/matplotlib/files/9292469/new.pdf">new.pdf</a></p>
<p dir="auto">the color bar between -500 to 0 is as long as from 0 to 4000, although should be as long as 0 to 500</p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/23103092/183694722-37a206f2-b783-4d27-a9ac-fc9d67a6f2ca.png"><img src="https://user-images.githubusercontent.com/23103092/183694722-37a206f2-b783-4d27-a9ac-fc9d67a6f2ca.png" alt="old" style="max-width: 100%;"></a></p>
<h3 dir="auto">Additional information</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Operating system</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">stable/dev</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Python version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Installation</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">When using <code class="notranslate">TwoSlopeNorm</code> with <code class="notranslate">pcolormesh</code>, I receive errors when I try to set the colorbar limits to both be on one side of the <code class="notranslate">vcenter</code> specified in <code class="notranslate">TwoSlopeNorm</code>.</p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
import matplotlib.colors as mcolors

x = [[0, 1, 2], [0, 1, 2], [0, 1, 2]]
y = [[0, 0, 0], [1, 1, 1], [2, 2, 2]]
data = [[-1, -2], [-2, -3]]

plt.pcolormesh(x, y, data, cmap=&quot;coolwarm&quot;, norm=mcolors.TwoSlopeNorm(vmin=-3, vcenter=0, vmax=1))
plt.colorbar()

plt.clim([-3, -1])  # this breaks
# plt.clim([-3, 1])  # this works fine
# plt.clim([1, 3])  # this also breaks"><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">matplotlib</span>.<span class="pl-s1">colors</span> <span class="pl-k">as</span> <span class="pl-s1">mcolors</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> [[<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>], [<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>], [<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>]]
<span class="pl-s1">y</span> <span class="pl-c1">=</span> [[<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>], [<span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>]]
<span class="pl-s1">data</span> <span class="pl-c1">=</span> [[<span class="pl-c1">-</span><span class="pl-c1">1</span>, <span class="pl-c1">-</span><span class="pl-c1">2</span>], [<span class="pl-c1">-</span><span class="pl-c1">2</span>, <span class="pl-c1">-</span><span class="pl-c1">3</span>]]

<span class="pl-s1">plt</span>.<span class="pl-en">pcolormesh</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>, <span class="pl-s1">data</span>, <span class="pl-s1">cmap</span><span class="pl-c1">=</span><span class="pl-s">"coolwarm"</span>, <span class="pl-s1">norm</span><span class="pl-c1">=</span><span class="pl-s1">mcolors</span>.<span class="pl-v">TwoSlopeNorm</span>(<span class="pl-s1">vmin</span><span class="pl-c1">=</span><span class="pl-c1">-</span><span class="pl-c1">3</span>, <span class="pl-s1">vcenter</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">vmax</span><span class="pl-c1">=</span><span class="pl-c1">1</span>))
<span class="pl-s1">plt</span>.<span class="pl-en">colorbar</span>()

<span class="pl-s1">plt</span>.<span class="pl-en">clim</span>([<span class="pl-c1">-</span><span class="pl-c1">3</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>])  <span class="pl-c"># this breaks</span>
<span class="pl-c"># plt.clim([-3, 1])  # this works fine</span>
<span class="pl-c"># plt.clim([1, 3])  # this also breaks</span></pre></div>
<h3 dir="auto">Actual outcome</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;/home/eytan/Documents/matplotlib_debug.py&quot;, line 11, in &lt;module&gt;
    plt.clim([-3, -1])  # this breaks
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/pyplot.py&quot;, line 2131, in clim
    im.set_clim(vmin, vmax)
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cm.py&quot;, line 525, in set_clim
    self.norm.vmax = colors._sanitize_extrema(vmax)
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colors.py&quot;, line 1161, in vmax
    self._changed()
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colors.py&quot;, line 1178, in _changed
    self.callbacks.process('changed')
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py&quot;, line 292, in process
    self.exception_handler(exc)
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py&quot;, line 96, in _exception_printer
    raise exc
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py&quot;, line 287, in process
    func(*args, **kwargs)
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cm.py&quot;, line 618, in changed
    self.callbacks.process('changed', self)
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py&quot;, line 292, in process
    self.exception_handler(exc)
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py&quot;, line 96, in _exception_printer
    raise exc
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py&quot;, line 287, in process
    func(*args, **kwargs)
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colorbar.py&quot;, line 551, in update_normal
    self.draw_all()
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colorbar.py&quot;, line 608, in draw_all
    self._add_solids(X, Y, self._values[ind, np.newaxis])
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colorbar.py&quot;, line 624, in _add_solids
    self.solids = self.ax.pcolormesh(
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/__init__.py&quot;, line 1412, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/axes/_axes.py&quot;, line 6058, in pcolormesh
    X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
  File &quot;/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/axes/_axes.py&quot;, line 5533, in _pcolorargs
    raise ValueError(
ValueError: x and y arguments to pcolormesh cannot have non-finite values or be of type numpy.ma.core.MaskedArray with masked values"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "/home/eytan/Documents/matplotlib_debug.py", line 11, in &lt;module&gt;
    plt.clim([-3, -1])  # this breaks
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/pyplot.py", line 2131, in clim
    im.set_clim(vmin, vmax)
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cm.py", line 525, in set_clim
    self.norm.vmax = colors._sanitize_extrema(vmax)
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colors.py", line 1161, in vmax
    self._changed()
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colors.py", line 1178, in _changed
    self.callbacks.process('changed')
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 292, in process
    self.exception_handler(exc)
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 96, in _exception_printer
    raise exc
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 287, in process
    func(*args, **kwargs)
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cm.py", line 618, in changed
    self.callbacks.process('changed', self)
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 292, in process
    self.exception_handler(exc)
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 96, in _exception_printer
    raise exc
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 287, in process
    func(*args, **kwargs)
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colorbar.py", line 551, in update_normal
    self.draw_all()
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colorbar.py", line 608, in draw_all
    self._add_solids(X, Y, self._values[ind, np.newaxis])
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/colorbar.py", line 624, in _add_solids
    self.solids = self.ax.pcolormesh(
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/__init__.py", line 1412, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 6058, in pcolormesh
    X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
  File "/home/eytan/miniconda3/envs/mpl_debug/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 5533, in _pcolorargs
    raise ValueError(
ValueError: x and y arguments to pcolormesh cannot have non-finite values or be of type numpy.ma.core.MaskedArray with masked values
</code></pre></div>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">A <code class="notranslate">pcolormesh</code> figure with a colorbar limit with a minimum of -3 and maximum of -1.</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">Works in version 3.4.3, breaks in version 3.5.0. Could it be related to the fix for <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1057493855" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/21671" data-hovercard-type="issue" data-hovercard-url="/matplotlib/matplotlib/issues/21671/hovercard" href="https://github.com/matplotlib/matplotlib/issues/21671">#21671</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1058183168" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/21676" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/21676/hovercard" href="https://github.com/matplotlib/matplotlib/pull/21676">#21676</a>? It seems like a similar issue and also showed up in version 3.5.0.</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Ubuntu 20.04</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.2</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">TkAgg</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.9.12</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Installation</h3>
<p dir="auto">pip</p>