Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug report
Bug summary
Contour plots don't interact nicely withmatplotlib.colors.LogNorm
.
Likely related to#19748
Code for reproduction
importmatplotlib.pyplotaspltfrommatplotlib.colorsimportLogNormimportnumpyasnp# BUG: setting levels as a scalar has no effect and no warning or error is printedfig,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 incorrectfig,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: thelevels
kwarg should be usable in both cases.
I note that the output from the first snippet is consistent with the case where neitherlevels
ornorm
are specified, and is correct in that case, so it's definetely notcompletely 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.