Skip to content

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

Closed

Description

@lanemeier

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

Activity

  1. github-actions commented on Jan 20, 2022

    @github-actions
    Contributor

    Welcome to Astropy 👋 and thank you for your first issue!

    A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details.

    GitHub issues in the Astropy repository are used to track bug reports and feature requests; If your issue poses a question about how to use Astropy, please instead raise your question in the Astropy Discourse user forum and close this issue.

    If you feel that this issue has not been responded to in a timely manner, please leave a comment mentioning our software support engineer @embray, or send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

  2. pllim commented on Jan 20, 2022

    @pllim
    Member

    I think this is related to matplotlib/matplotlib#21723 . We have axes.grid set to True, so not sure why we are even seeing this.

    'axes.grid': True,

  3. lanemeier commented on Jan 20, 2022

    @lanemeier
    Author

    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

  4. pllim commented on Jan 21, 2022

    @pllim
    Member

    Yes, definitely good to know of these warnings earlier than later. Thanks for the report!

  5. pllim commented on Jan 25, 2022

    @pllim
    Member

    I cannot tell if matplotlib/matplotlib#22285 had fixed your problem. Are you able to test out your use case with dev version of matplotlib? Or maybe even better, add a test that would trigger this in our test suite and see which jobs still fail? Thanks!

  6. lanemeier commented on Jan 26, 2022

    @lanemeier
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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