question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

astropy_mpl_style visualization causes plt.colorbar() MatplotlibDeprecationWarning in Matplotlib 3.5

See original GitHub issue

Description

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

  1. Install Matplotlib version 3.5
  2. 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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lanemeiercommented, Jan 26, 2022

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.

1reaction
lanemeiercommented, Jan 20, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found