FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: Matplotlib >= 3.5.0 drops scientific notation for colorbars using log ticks · Issue #24002 · matplotlib/matplotlib · GitHub

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

Closed as not planned

Description

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.

Expected outcome

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

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)

Activity

  1. jklymak commented on Sep 25, 2022

    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL