<h3 dir="auto">Bug summary</h3>
<p dir="auto">If you contour a uniform field i.e. <code class="notranslate">ax.contour(z=[[1, 1], [1,1]]))</code> it works fine, although the output is not very interesting. If you add a colorbar to this, you receive an error. Without the colorbar call there is  no error.</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

fig, ax = plt.subplots()
cs = ax.contour([[1, 1], [1, 1]])
fig.colorbar(cs, ax=ax)
plt.show()"><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-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">contour</span>([[<span class="pl-c1">1</span>, <span class="pl-c1">1</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">1</span>]])
<span class="pl-s1">fig</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-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto">bug.py:18: UserWarning: No contour levels were found within the data range.<br>
cs = ax.contour([[1, 1], [1, 1]])<br>
/home/iant/github/matplotlib/lib/matplotlib/colorbar.py:1224: RuntimeWarning: invalid value encountered in divide<br>
y = y / (self._boundaries[self._inside][-1] -<br>
Traceback (most recent call last):<br>
File "bug.py", line 19, in <br>
fig.colorbar(cs, ax=ax)<br>
File "/home/iant/github/matplotlib/lib/matplotlib/figure.py", line 1276, in colorbar<br>
cb = cbar.Colorbar(cax, mappable, **cb_kw)<br>
File "/home/iant/github/matplotlib/lib/matplotlib/_api/deprecation.py", line 384, in wrapper<br>
return func(*inner_args, **inner_kwargs)<br>
File "/home/iant/github/matplotlib/lib/matplotlib/colorbar.py", line 396, in <strong>init</strong><br>
self._draw_all()<br>
File "/home/iant/github/matplotlib/lib/matplotlib/colorbar.py", line 535, in _draw_all<br>
X, Y = self._mesh()<br>
File "/home/iant/github/matplotlib/lib/matplotlib/colorbar.py", line 1110, in _mesh<br>
y, _ = self._proportional_y()<br>
File "/home/iant/github/matplotlib/lib/matplotlib/colorbar.py", line 1246, in _proportional_y<br>
automin = yscaled[1] - yscaled[0]<br>
IndexError: index 1 is out of bounds for axis 0 with size 1</p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">Colorbar should be displayed as normal.</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">Essentially the colorbar data range is zero, so when trying to determine the y-position of a particular contour level there is a divide by zero.</p>
<p dir="auto">This has probably been a problem for years. It is a silly test case as who wants to contour a uniform field, but we should handle it more gracefully.</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">N/A</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.6.0.dev3132+gf8cf0ee5e7</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">N/A</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.8.10</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto">N/A</p>
<h3 dir="auto">Installation</h3>
<p dir="auto">from source (.tar.gz)</p>
<p dir="auto">It would be great if you could copy the functionality as it exists in Matlab:<br>
In the toolbar there is a 'Data Cursor' button.<br>
This allows you to click on data points on the plot and it shows values.<br>
It also allows you to move around the plot by using the arrow keys.<br>
This is really helpful for scanning sample values quickly.</p>