<h3 dir="auto">Bug summary</h3>
<p dir="auto">This possible bug seems to be related to some incompatibility between the “extend” argument in “plt.figure.colorbar” and “.ax.invert_yaxis()” functions. More specifically, if I just extend the max of colorbar (second figure) or just invert the y-axis of the colorbar, everything work fine. However, if I do this two at the same time, the colorbar would be inverted while the extended arrow is not(figure one).</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="# Generate X/Y point mesh grid
x = np.linspace(-4.5, 1.5, 400)  
y = np.linspace(-8, -2, 400)
X, Y = np.meshgrid(x, y)
potential, rate_determining_step = calculate_limiting_potential_from_linear_relations(X, Y, free_energy_dict)[0], calculate_limiting_potential_from_linear_relations(X, Y, free_energy_dict)[1]   # calculate limiting potential for each point on the mesh grid
 
# Create backup ground volcano plot
fig = plt.figure(figsize=[8, 6])
background = fig.add_subplot(111)  # add sub plot
 
# Add contour plot
contour = background.contourf(X, Y, potential, levels=512, cmap=&quot;rainbow&quot;)  # create filled contour (reverse rainbow)
 
# Create colorbar
cbar = fig.colorbar(contour, shrink=0.95, aspect=15, ticks=[1, 2, 3, 4])  # create colorbar (shrink/aspect for the size of the bar)
cbar.set_label(&quot;Limiting Potential (eV)&quot;, fontsize=16)  # add label to the colorbar
cbar.ax.tick_params(labelsize=12)  # set tick label size
cbar.ax.invert_yaxis()  # put the colorbar upside down"><pre class="notranslate"><span class="pl-c"># Generate X/Y point mesh grid</span>
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">-</span><span class="pl-c1">4.5</span>, <span class="pl-c1">1.5</span>, <span class="pl-c1">400</span>)  
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">-</span><span class="pl-c1">8</span>, <span class="pl-c1">-</span><span class="pl-c1">2</span>, <span class="pl-c1">400</span>)
<span class="pl-v">X</span>, <span class="pl-v">Y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">meshgrid</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>)
<span class="pl-s1">potential</span>, <span class="pl-s1">rate_determining_step</span> <span class="pl-c1">=</span> <span class="pl-en">calculate_limiting_potential_from_linear_relations</span>(<span class="pl-v">X</span>, <span class="pl-v">Y</span>, <span class="pl-s1">free_energy_dict</span>)[<span class="pl-c1">0</span>], <span class="pl-en">calculate_limiting_potential_from_linear_relations</span>(<span class="pl-v">X</span>, <span class="pl-v">Y</span>, <span class="pl-s1">free_energy_dict</span>)[<span class="pl-c1">1</span>]   <span class="pl-c"># calculate limiting potential for each point on the mesh grid</span>
 
<span class="pl-c"># Create backup ground volcano plot</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">figsize</span><span class="pl-c1">=</span>[<span class="pl-c1">8</span>, <span class="pl-c1">6</span>])
<span class="pl-s1">background</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-c1">111</span>)  <span class="pl-c"># add sub plot</span>
 
<span class="pl-c"># Add contour plot</span>
<span class="pl-s1">contour</span> <span class="pl-c1">=</span> <span class="pl-s1">background</span>.<span class="pl-en">contourf</span>(<span class="pl-v">X</span>, <span class="pl-v">Y</span>, <span class="pl-s1">potential</span>, <span class="pl-s1">levels</span><span class="pl-c1">=</span><span class="pl-c1">512</span>, <span class="pl-s1">cmap</span><span class="pl-c1">=</span><span class="pl-s">"rainbow"</span>)  <span class="pl-c"># create filled contour (reverse rainbow)</span>
 
<span class="pl-c"># Create colorbar</span>
<span class="pl-s1">cbar</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">contour</span>, <span class="pl-s1">shrink</span><span class="pl-c1">=</span><span class="pl-c1">0.95</span>, <span class="pl-s1">aspect</span><span class="pl-c1">=</span><span class="pl-c1">15</span>, <span class="pl-s1">ticks</span><span class="pl-c1">=</span>[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>])  <span class="pl-c"># create colorbar (shrink/aspect for the size of the bar)</span>
<span class="pl-s1">cbar</span>.<span class="pl-en">set_label</span>(<span class="pl-s">"Limiting Potential (eV)"</span>, <span class="pl-s1">fontsize</span><span class="pl-c1">=</span><span class="pl-c1">16</span>)  <span class="pl-c"># add label to the colorbar</span>
<span class="pl-s1">cbar</span>.<span class="pl-s1">ax</span>.<span class="pl-en">tick_params</span>(<span class="pl-s1">labelsize</span><span class="pl-c1">=</span><span class="pl-c1">12</span>)  <span class="pl-c"># set tick label size</span>
<span class="pl-s1">cbar</span>.<span class="pl-s1">ax</span>.<span class="pl-en">invert_yaxis</span>()  <span class="pl-c"># put the colorbar upside down</span></pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/80093591/157570730-408cf9a3-3be1-4596-8a99-68f314124ccd.png"><img src="https://user-images.githubusercontent.com/80093591/157570730-408cf9a3-3be1-4596-8a99-68f314124ccd.png" alt="figure3" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/80093591/157570816-8e9715c8-ac97-48d1-834f-8727d59a640f.png"><img src="https://user-images.githubusercontent.com/80093591/157570816-8e9715c8-ac97-48d1-834f-8727d59a640f.png" alt="figure1" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">The arrow should inverse with the colorbar itself.</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Windows11</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">Matplotlib 3.5.1</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Python version</h3>
<p dir="auto">Python 3.10</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>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">The "over value" and the "under value" of colormap are not correctly shown when using ax.invert_yaxis (invert_xaxis if the colorbar is horizontal) function.</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 numpy as np
import matplotlib.pyplot as plt
im=plt.imshow(np.arange(10000).reshape(100,100),vmax=9000,vmin=1000)
cb=plt.colorbar(im,extend='both')
cb.ax.invert_yaxis()"><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">im</span><span class="pl-c1">=</span><span class="pl-s1">plt</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">10000</span>).<span class="pl-en">reshape</span>(<span class="pl-c1">100</span>,<span class="pl-c1">100</span>),<span class="pl-s1">vmax</span><span class="pl-c1">=</span><span class="pl-c1">9000</span>,<span class="pl-s1">vmin</span><span class="pl-c1">=</span><span class="pl-c1">1000</span>)
<span class="pl-s1">cb</span><span class="pl-c1">=</span><span class="pl-s1">plt</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">im</span>,<span class="pl-s1">extend</span><span class="pl-c1">=</span><span class="pl-s">'both'</span>)
<span class="pl-s1">cb</span>.<span class="pl-s1">ax</span>.<span class="pl-en">invert_yaxis</span>()</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/31818986/147364868-31b36095-c446-401f-99fe-28b344e20c06.png"><img src="https://user-images.githubusercontent.com/31818986/147364868-31b36095-c446-401f-99fe-28b344e20c06.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">The "over value" and the "under value" could be shown in the right location by the way. The "under value" is expected to be at the top, if the y axis is reverted.</p>
<p dir="auto">If this is not a bug, would it be a feature?</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">CentOs</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.0</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.9.7</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>