<h3 dir="auto">Bug summary</h3>
<p dir="auto">Changing the parameter 'levels' when using contourf and a colorbar with  norm=colors.LogNorm has no effect on the final figure. '</p>
<h3 dir="auto">Code for reproduction</h3>
<p dir="auto">This code is inspired from the Colormap Normalizations example from <a href="https://matplotlib.org/stable/gallery/userdemo/colormap_normalizations.html#sphx-glr-gallery-userdemo-colormap-normalizations-py" rel="nofollow">https://matplotlib.org/stable/gallery/userdemo/colormap_normalizations.html#sphx-glr-gallery-userdemo-colormap-normalizations-py</a> adding the norm=colors.LogNorm parameter.</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
import matplotlib.colors as colors

N = 100
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]

Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
Z = Z1 + 50 * Z2

fig, ax = plt.subplots(1, 2)

pcm = ax[0].contourf(X, Y, Z, levels=10,
                   norm=colors.LogNorm(vmin=Z.min(), vmax=Z.max()),
                   cmap='PuBu_r')
fig.colorbar(pcm, ax=ax[0], extend='max')

pcm = ax[1].contourf(X, Y, Z, levels=20,
                   norm=colors.LogNorm(vmin=Z.min(), vmax=Z.max()),
                   cmap='PuBu_r')
fig.colorbar(pcm, ax=ax[1], extend='max')

plt.tight_layout()"><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">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">colors</span> <span class="pl-k">as</span> <span class="pl-s1">colors</span>

<span class="pl-v">N</span> <span class="pl-c1">=</span> <span class="pl-c1">100</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-s1">mgrid</span>[<span class="pl-c1">-</span><span class="pl-c1">3</span>:<span class="pl-c1">3</span>:<span class="pl-en">complex</span>(<span class="pl-c1">0</span>, <span class="pl-v">N</span>), <span class="pl-c1">-</span><span class="pl-c1">2</span>:<span class="pl-c1">2</span>:<span class="pl-en">complex</span>(<span class="pl-c1">0</span>, <span class="pl-v">N</span>)]

<span class="pl-v">Z1</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">exp</span>(<span class="pl-c1">-</span><span class="pl-v">X</span><span class="pl-c1">**</span><span class="pl-c1">2</span> <span class="pl-c1">-</span> <span class="pl-v">Y</span><span class="pl-c1">**</span><span class="pl-c1">2</span>)
<span class="pl-v">Z2</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">exp</span>(<span class="pl-c1">-</span>(<span class="pl-v">X</span> <span class="pl-c1">*</span> <span class="pl-c1">10</span>)<span class="pl-c1">**</span><span class="pl-c1">2</span> <span class="pl-c1">-</span> (<span class="pl-v">Y</span> <span class="pl-c1">*</span> <span class="pl-c1">10</span>)<span class="pl-c1">**</span><span class="pl-c1">2</span>)
<span class="pl-v">Z</span> <span class="pl-c1">=</span> <span class="pl-v">Z1</span> <span class="pl-c1">+</span> <span class="pl-c1">50</span> <span class="pl-c1">*</span> <span class="pl-v">Z2</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-c1">1</span>, <span class="pl-c1">2</span>)

<span class="pl-s1">pcm</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>[<span class="pl-c1">0</span>].<span class="pl-en">contourf</span>(<span class="pl-v">X</span>, <span class="pl-v">Y</span>, <span class="pl-v">Z</span>, <span class="pl-s1">levels</span><span class="pl-c1">=</span><span class="pl-c1">10</span>,
                   <span class="pl-s1">norm</span><span class="pl-c1">=</span><span class="pl-s1">colors</span>.<span class="pl-v">LogNorm</span>(<span class="pl-s1">vmin</span><span class="pl-c1">=</span><span class="pl-v">Z</span>.<span class="pl-en">min</span>(), <span class="pl-s1">vmax</span><span class="pl-c1">=</span><span class="pl-v">Z</span>.<span class="pl-en">max</span>()),
                   <span class="pl-s1">cmap</span><span class="pl-c1">=</span><span class="pl-s">'PuBu_r'</span>)
<span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">pcm</span>, <span class="pl-s1">ax</span><span class="pl-c1">=</span><span class="pl-s1">ax</span>[<span class="pl-c1">0</span>], <span class="pl-s1">extend</span><span class="pl-c1">=</span><span class="pl-s">'max'</span>)

<span class="pl-s1">pcm</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>[<span class="pl-c1">1</span>].<span class="pl-en">contourf</span>(<span class="pl-v">X</span>, <span class="pl-v">Y</span>, <span class="pl-v">Z</span>, <span class="pl-s1">levels</span><span class="pl-c1">=</span><span class="pl-c1">20</span>,
                   <span class="pl-s1">norm</span><span class="pl-c1">=</span><span class="pl-s1">colors</span>.<span class="pl-v">LogNorm</span>(<span class="pl-s1">vmin</span><span class="pl-c1">=</span><span class="pl-v">Z</span>.<span class="pl-en">min</span>(), <span class="pl-s1">vmax</span><span class="pl-c1">=</span><span class="pl-v">Z</span>.<span class="pl-en">max</span>()),
                   <span class="pl-s1">cmap</span><span class="pl-c1">=</span><span class="pl-s">'PuBu_r'</span>)
<span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">pcm</span>, <span class="pl-s1">ax</span><span class="pl-c1">=</span><span class="pl-s1">ax</span>[<span class="pl-c1">1</span>], <span class="pl-s1">extend</span><span class="pl-c1">=</span><span class="pl-s">'max'</span>)

<span class="pl-s1">plt</span>.<span class="pl-en">tight_layout</span>()</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto">The number of levels do not change even if the parameter 'levels' in contourf is changed.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/40710281/149321276-61f9e0dc-5f26-473e-8462-49ca3f36ee09.png"><img src="https://user-images.githubusercontent.com/40710281/149321276-61f9e0dc-5f26-473e-8462-49ca3f36ee09.png" alt="Figure_1" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">I expected to see that changing the 'levels' parameters in contourf actually change the number of levels in the plot (to obtain the figures below: same code has before but remove the norm=colors.LogNorm(vmin=Z.min(), vmax=Z.max()) parameter and plot X^2+Y^2 rather than Z).</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/40710281/149321312-0b9054d5-95cd-4964-b2fe-a489089fed68.png"><img src="https://user-images.githubusercontent.com/40710281/149321312-0b9054d5-95cd-4964-b2fe-a489089fed68.png" alt="Figure_2" 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">Windows 10</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.0</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">Qt5Agg</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.10.1</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 report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">It does not seem possible to use LogLocator to generate a specific number of log-spaced tick locations without a live axis.</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 matplotlib as mpl
ticker = mpl.ticker.LogLocator(numticks=2)
ticker.tick_values(1, 10)"><pre class="notranslate"><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">ticker</span> <span class="pl-c1">=</span> <span class="pl-s1">mpl</span>.<span class="pl-s1">ticker</span>.<span class="pl-v">LogLocator</span>(<span class="pl-s1">numticks</span><span class="pl-c1">=</span><span class="pl-c1">2</span>)
<span class="pl-s1">ticker</span>.<span class="pl-en">tick_values</span>(<span class="pl-c1">1</span>, <span class="pl-c1">10</span>)</pre></div>
<p dir="auto">array([   0.1,    1. ,   10. ,  100. ])</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">array([   1. ,   10. ,  ])</p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Matplotlib version: 2.2.2</li>
<li>Python version: 3.6</li>
</ul>