Description
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()
# 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()
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.