<h3 dir="auto">Bug summary</h3>
<p dir="auto">When using logarithmic scaling of the data with 2D plots, the ticks for the colorbar are not written in scientific notation. Prior to Matplotlib 3.5.0 (e.g. 3.4.3), scientific notation was used, as one would expect. The problem persists in 3.6.</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="# Sample code for 2D plotting with log scaling,
# with the log scaling implemented
# using two different methods.

import numpy as np
import matplotlib
import matplotlib.pyplot as plt

n = 100
np.random.seed(42)
x = np.random.random(n)
y = np.random.random(n)
z = np.logspace(np.log10(1e-7), np.log10(1e+7), n)

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

tcs = axes[0].tricontourf(
    x, y, z,
    norm=matplotlib.colors.LogNorm(vmin=z.min(), vmax=z.max()),
)
cbar = fig.colorbar(tcs, ax=axes[0])

tcs = axes[1].tricontourf(
    x, y, z,
    locator=matplotlib.ticker.LogLocator(),
)
cbar = fig.colorbar(tcs, ax=axes[1])

plt.savefig('test.png')"><pre class="notranslate"><span class="pl-c"># Sample code for 2D plotting with log scaling,</span>
<span class="pl-c"># with the log scaling implemented</span>
<span class="pl-c"># using two different methods.</span>

<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-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">n</span> <span class="pl-c1">=</span> <span class="pl-c1">100</span>
<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">seed</span>(<span class="pl-c1">42</span>)
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random</span>(<span class="pl-s1">n</span>)
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random</span>(<span class="pl-s1">n</span>)
<span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">logspace</span>(<span class="pl-s1">np</span>.<span class="pl-en">log10</span>(<span class="pl-c1">1e-7</span>), <span class="pl-s1">np</span>.<span class="pl-en">log10</span>(<span class="pl-c1">1e+7</span>), <span class="pl-s1">n</span>)

<span class="pl-s1">fig</span>, <span class="pl-s1">axes</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>(<span class="pl-c1">2</span>, <span class="pl-c1">1</span>)

<span class="pl-s1">tcs</span> <span class="pl-c1">=</span> <span class="pl-s1">axes</span>[<span class="pl-c1">0</span>].<span class="pl-en">tricontourf</span>(
    <span class="pl-s1">x</span>, <span class="pl-s1">y</span>, <span class="pl-s1">z</span>,
    <span class="pl-s1">norm</span><span class="pl-c1">=</span><span class="pl-s1">matplotlib</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-s1">z</span>.<span class="pl-en">min</span>(), <span class="pl-s1">vmax</span><span class="pl-c1">=</span><span class="pl-s1">z</span>.<span class="pl-en">max</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">tcs</span>, <span class="pl-s1">ax</span><span class="pl-c1">=</span><span class="pl-s1">axes</span>[<span class="pl-c1">0</span>])

<span class="pl-s1">tcs</span> <span class="pl-c1">=</span> <span class="pl-s1">axes</span>[<span class="pl-c1">1</span>].<span class="pl-en">tricontourf</span>(
    <span class="pl-s1">x</span>, <span class="pl-s1">y</span>, <span class="pl-s1">z</span>,
    <span class="pl-s1">locator</span><span class="pl-c1">=</span><span class="pl-s1">matplotlib</span>.<span class="pl-s1">ticker</span>.<span class="pl-v">LogLocator</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">tcs</span>, <span class="pl-s1">ax</span><span class="pl-c1">=</span><span class="pl-s1">axes</span>[<span class="pl-c1">1</span>])

<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'test.png'</span>)</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto">Here is the outcome of the above in Matplotlib 3.5.0 or 3.6.0 (the results are identical). The image properly shows logarithmic values, and the colorbar ticks are in log scale as well, but the colorbar tick labels are not written using scientific notation. One major drawback is that all tics but the highest two gets written as <code class="notranslate">0.00</code>, while they are really <code class="notranslate">0.001</code>, <code class="notranslate">0.0001</code>, etc.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/9202794/192121946-0932593b-aabc-427e-825e-fb1cb6573669.png"><img src="https://user-images.githubusercontent.com/9202794/192121946-0932593b-aabc-427e-825e-fb1cb6573669.png" alt="test_3 5 0" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">Same as above but run with Matplotlib 3.4.3. Both methods work to produce scientific notation, as desired.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/9202794/192121978-ce61c8fd-0af6-49b2-acc9-03d4ac4b49b0.png"><img src="https://user-images.githubusercontent.com/9202794/192121978-ce61c8fd-0af6-49b2-acc9-03d4ac4b49b0.png" alt="test_3 4 3" style="max-width: 100%;"></a></p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Linux Mint 20</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">As described above</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">Agg and Qt5Agg</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.8.5 and 3.9.9</p>
<h3 dir="auto">Installation</h3>
<p dir="auto">from source (.tar.gz)</p>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">The colour bar ticks are weirdly formatted when using a logarithmic scale when using version 3.5.0 or later.</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="Taken from https://matplotlib.org/stable/gallery/images_contours_and_fields/contourf_log.html


import matplotlib.pyplot as plt
import numpy as np
from numpy import ma
from matplotlib import ticker, cm

N = 100
x = np.linspace(-3.0, 3.0, N)
y = np.linspace(-2.0, 2.0, N)

X, Y = np.meshgrid(x, y)

# A low hump with a spike coming out.
# Needs to have z/colour axis on a log scale so we see both hump and spike.
# linear scale only shows the spike.
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
z = Z1 + 50 * Z2

# Put in some negative values (lower left corner) to cause trouble with logs:
z[:5, :5] = -1

# The following is not strictly essential, but it will eliminate
# a warning.  Comment it out to see the warning.
z = ma.masked_where(z &lt;= 0, z)


# Automatic selection of levels works; setting the
# log locator tells contourf to use a log scale:
fig, ax = plt.subplots()
cs = ax.contourf(X, Y, z, locator=ticker.LogLocator(), cmap=cm.PuBu_r)

cbar = fig.colorbar(cs)

plt.show()"><pre class="notranslate"><span class="pl-v">Taken</span> <span class="pl-s1">from</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">gallery</span><span class="pl-c1">/</span><span class="pl-s1">images_contours_and_fields</span><span class="pl-c1">/</span><span class="pl-s1">contourf_log</span>.<span class="pl-s1">html</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">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">from</span> <span class="pl-s1">numpy</span> <span class="pl-k">import</span> <span class="pl-s1">ma</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">ticker</span>, <span class="pl-s1">cm</span>

<span class="pl-v">N</span> <span class="pl-c1">=</span> <span class="pl-c1">100</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">3.0</span>, <span class="pl-c1">3.0</span>, <span class="pl-v">N</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">2.0</span>, <span class="pl-c1">2.0</span>, <span class="pl-v">N</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-c"># A low hump with a spike coming out.</span>
<span class="pl-c"># Needs to have z/colour axis on a log scale so we see both hump and spike.</span>
<span class="pl-c"># linear scale only shows the spike.</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-s1">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-c"># Put in some negative values (lower left corner) to cause trouble with logs:</span>
<span class="pl-s1">z</span>[:<span class="pl-c1">5</span>, :<span class="pl-c1">5</span>] <span class="pl-c1">=</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>

<span class="pl-c"># The following is not strictly essential, but it will eliminate</span>
<span class="pl-c"># a warning.  Comment it out to see the warning.</span>
<span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">ma</span>.<span class="pl-en">masked_where</span>(<span class="pl-s1">z</span> <span class="pl-c1">&lt;=</span> <span class="pl-c1">0</span>, <span class="pl-s1">z</span>)


<span class="pl-c"># Automatic selection of levels works; setting the</span>
<span class="pl-c"># log locator tells contourf to use a log scale:</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">contourf</span>(<span class="pl-v">X</span>, <span class="pl-v">Y</span>, <span class="pl-s1">z</span>, <span class="pl-s1">locator</span><span class="pl-c1">=</span><span class="pl-s1">ticker</span>.<span class="pl-v">LogLocator</span>(), <span class="pl-s1">cmap</span><span class="pl-c1">=</span><span class="pl-s1">cm</span>.<span class="pl-v">PuBu_r</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">cs</span>)

<span class="pl-s1">plt</span>.<span class="pl-en">show</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/40028739/177347713-40db322e-65a3-4763-af66-8c8bb3daab0c.png"><img src="https://user-images.githubusercontent.com/40028739/177347713-40db322e-65a3-4763-af66-8c8bb3daab0c.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">Running the exact same code on 3.4.2 produces the expected behaviour<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/40028739/177347830-9550a81c-7340-49f8-903e-6d39637493f4.png"><img src="https://user-images.githubusercontent.com/40028739/177347830-9550a81c-7340-49f8-903e-6d39637493f4.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">This worked perfectly on version 3.4.2</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Windows</p>
<h3 dir="auto">Matplotlib Version</h3>
<blockquote>
<p dir="auto">3.5.0</p>
</blockquote>
<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">pip</p>