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.
Code for reproduction
# Sample code for 2D plotting with log scaling,# with the log scaling implemented# using two different methods.importnumpyasnpimportmatplotlibimportmatplotlib.pyplotaspltn=100np.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')
Actual outcome
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 0.00, while they are really 0.001, 0.0001, etc.
Expected outcome
Same as above but run with Matplotlib 3.4.3. Both methods work to produce scientific notation, as desired.
Activity
jklymak commented on Sep 25, 2022
This is a duplicate of #23389. Working on a fix, but getting all the edge cases correct has been challenging: #23390
I'll close here, but please ping the other issue if it is not fixed "soon"...