Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Matplotlib >= 3.5.0 drops scientific notation for colorbars using log ticks #24002

Closed
jmd-dk opened this issue Sep 24, 2022 · 1 comment

Comments

@jmd-dk
Copy link

jmd-dk commented Sep 24, 2022

Bug summary

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.

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')

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.
test_3 5 0

Expected outcome

Same as above but run with Matplotlib 3.4.3. Both methods work to produce scientific notation, as desired.
test_3 4 3

Operating system

Linux Mint 20

Matplotlib Version

As described above

Matplotlib Backend

Agg and Qt5Agg

Python version

3.8.5 and 3.9.9

Installation

from source (.tar.gz)

@jklymak
Copy link
Member

jklymak commented 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"...

@jklymak jklymak closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants