Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: Contours with LogNorm #19856

Copy link
Copy link
Open
Open
Copy link
@neutrinoceros

Description

@neutrinoceros
Issue body actions

Bug report

Bug summary
Contour plots don't interact nicely with matplotlib.colors.LogNorm.
Likely related to #19748

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import numpy as np

# BUG: setting levels as a scalar has no effect and no warning or error is printed
fig, ax = plt.subplots()
im = ax.contourf(x, y, data, norm=LogNorm(), levels=4)
fig.colorbar(im, ax=ax)
plt.show()

mpl_logcontours_bug1

# kinda buggy too: setting levels as an array does have some of the desired effects
# but ticks and ticklabels are incorrect
fig, ax = plt.subplots()
levels = np.logspace(np.log10(data.min()), np.log10(data.max()), 5)
im = ax.contourf(x, y, data, norm=LogNorm(), levels=levels)
fig.colorbar(im, ax=ax)
plt.show()

mpl_logcontours_bug2

Expected outcome

The experience should be comparable with what happens when the norm isn't specified: the levels kwarg should be usable in both cases.
I note that the output from the first snippet is consistent with the case where neither levels or norm are specified, and is correct in that case, so it's definetely not completely broken and I hope the fix is somewhat straightforward.

I'm happy to take a look at the source and see if I can come up with an easy patch, but I'm not sure when I'll have time to dive in there myself. Any piece advice from maintainers or contributors is more than welcome !

Matplotlib version

  • Operating system: MacOS
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.4.1
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.9.1
  • Jupyter version (if applicable): NA
  • Other libraries:

I installed matplotlib using pip.

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.