astropy_mpl_style visualization causes plt.colorbar() MatplotlibDeprecationWarning in Matplotlib 3.5
See original GitHub issueDescription
The astropy.visualization.astropy_mpl_style dictionary has ‘axes.grid’ set to True, this triggers a plt.colorbar() MatplotlibDeprecationWarning message for pyplot.imshow in Matplotlib version 3.5. Examples such as ones found here reference will trigger the warning message.
MatplotlibDeprecationWarning: Auto-removal of
grids by pcolor() and pcolormesh() is deprecated since 3.5 and will be removed t
wo minor releases later; please call grid(False) first.
plt.colorbar()
Expected behavior
No deprecation warning message.
Actual behavior
Steps to Reproduce
- Install Matplotlib version 3.5
- Run the following code
import matplotlib.pyplot as plt
from astropy.visualization import astropy_mpl_style
plt.style.use(astropy_mpl_style)
from astropy.utils.data import get_pkg_data_filename
from astropy.io import fits
image_file = get_pkg_data_filename('tutorials/FITS-images/HorseHead.fits')
fits.info(image_file)
image_data = fits.getdata(image_file, ext=0)
plt.figure()
plt.imshow(image_data, cmap='gray')
plt.colorbar()
System Details
Windows-10-10.0.18362-SP0 Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)] Numpy 1.20.3 pyerfa 2.0.0 astropy 5.0 Scipy 1.7.3 Matplotlib 3.5.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Using AstroPy with matplotlib, I get a warning to call grid(False ...
I get a warning: line 19 plt.colorbar() MatplotlibDeprecationWarning: Auto-removal of grids by pcolor() and pcolormesh() is deprecated since 3.5 ...
Read more >matplotlib.pyplot.colorbar — Matplotlib 3.6.2 documentation
For discrete colorbars ( BoundaryNorm or contours), 'uniform' gives each color the same space; 'proportional' makes the space proportional to the data interval....
Read more >Matplotlib.pyplot.colorbar() function in Python - GeeksforGeeks
Colorbars are a visualization of the mapping from scalar values to colors. In Matplotlib they are drawn into a dedicated axis.
Read more >Fix your matplotlib colorbars! - Joseph Long
%matplotlib inline %config InlineBackend.figure_format='retina' import numpy as np from matplotlib import pyplot as plt import matplotlib · data ...
Read more >Customizing Colorbars | Python Data Science Handbook
import matplotlib.pyplot as plt plt.style.use('classic') ... 3.5)) plt.subplot(1, 2, 1) plt.imshow(I, cmap='RdBu') plt.colorbar() plt.subplot(1, 2, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I pulled down the latest master matplotlib-3.6.0.dev1433+g9844e9ffad and confirmed that the warning message is gone.
Wish I had more time to add the test into the suite.
Thanks for responding so quickly and mentioning this to matplotlib. I can work around it, but I wanted to alert the project about the potential issue with grids in styles. Users may find the warning concerning. See https://stackoverflow.com/q/69999315/15531842