Skip to content

matplotlib dev: What happened to figure.dpi ? #19928

Closed

Description

@pllim

This morning, we got a new error testing against matplotlib dev. Example log at https://app.circleci.com/pipelines/github/astropy/astropy/4691/workflows/582b72af-3420-4af5-a185-f0e41601edfd/jobs/86623

_______________________ test_no_numpy_warnings[contours] _______________________

ignore_matplotlibrc = None
tmpdir = local('/tmp/pytest-of-root/pytest-0/test_no_numpy_warnings_contour0')
grid_type = 'contours'

    @pytest.mark.parametrize('grid_type', ['lines', 'contours'])
    def test_no_numpy_warnings(ignore_matplotlibrc, tmpdir, grid_type):
        ax = plt.subplot(1, 1, 1, projection=WCS(TARGET_HEADER))
        ax.imshow(np.zeros((100, 200)))
        ax.coords.grid(color='white', grid_type=grid_type)
    
        with pytest.warns(None) as warning_lines:
>           plt.savefig(tmpdir.join('test.png').strpath)

../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/astropy/visualization/wcsaxes/tests/test_misc.py:80: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/pyplot.py:956: in savefig
    fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/backend_bases.py:2058: in draw_idle
    self.draw(*args, **kwargs)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:406: in draw
    self.figure.draw(self.renderer)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/artist.py:74: in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/artist.py:51: in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/figure.py:2727: in draw
    renderer, self, artists, self.suppressComposite)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/image.py:132: in _draw_list_compositing_images
    a.draw(renderer)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/astropy/visualization/wcsaxes/core.py:459: in draw
    super().draw(renderer, **kwargs)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/artist.py:51: in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/_api/deprecation.py:421: in wrapper
    return func(*inner_args, **inner_kwargs)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/axes/_base.py:3102: in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/image.py:132: in _draw_list_compositing_images
    a.draw(renderer)
../../.tox/py37-test-image-mpldev/lib/python3.7/site-packages/matplotlib/artist.py:51: in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <matplotlib.collections.PathCollection object at 0x7f51ca1ac128>
renderer = <matplotlib.backends.backend_agg.RendererAgg object at 0x7f51cc0a0ef0>

    @artist.allow_rasterization
    def draw(self, renderer):
>       self.set_sizes(self._sizes, self.figure.dpi)
E       AttributeError: 'NoneType' object has no attribute 'dpi'

bisect attempt

d49696a is the first bad commit

commit d49696aba62820ce4bab41ae4a8508743e39a0e4
Author: Jody Klymak <...>
Date:   Sun Mar 14 14:08:50 2021 -0700

    New doc gallery for plot_types

Update: I don't think this is true actually... I have no idea what is going on

I think I traced it to https://github.com/astropy/astropy/blob/796b585f989319b766979df2110e0b4fa94a43a1/astropy/visualization/mpl_style.py#L63 . However, I am not sure if I should simply remove this setting or there is a new way to set it. Any advise would be greatly appreciated. Thanks!

# Version 1 astropy plotting style for matplotlib
astropy_mpl_style_1 = {
    # ...
    # Other
    'savefig.dpi': 72,
}

Activity

  1. pllim commented on Apr 9, 2021

    @pllim
    Author
  2. pllim commented on Apr 9, 2021

    @pllim
    Author

    Update: Okay, I did manage to bisect and git said it is #19703 . I can't say I understand the details enough to formulate a fix based on this info. I might also have been bisecting it wrong so you can double check. Here are my scripts:

    run_me.sh:

    #!/bin/sh
    
    python run_me.py

    run_me.py:

    import matplotlib.pyplot as plt
    import numpy as np
    
    from astropy.io import fits
    from astropy.wcs import WCS
    
    TARGET_HEADER = fits.Header.fromstring("""
    NAXIS   =                    2
    NAXIS1  =                  200
    NAXIS2  =                  100
    CTYPE1  = 'RA---MOL'
    CRPIX1  =                  500
    CRVAL1  =                180.0
    CDELT1  =                 -0.4
    CUNIT1  = 'deg     '
    CTYPE2  = 'DEC--MOL'
    CRPIX2  =                  400
    CRVAL2  =                  0.0
    CDELT2  =                  0.4
    CUNIT2  = 'deg     '
    COORDSYS= 'icrs    '
    """, sep='\n')
    
    
    def run():
        ax = plt.subplot(1, 1, 1, projection=WCS(TARGET_HEADER))
        ax.imshow(np.zeros((100, 200)))
        ax.coords.grid(color='white', grid_type='contours')
    
        plt.savefig('test.png')
    
    
    if __name__ == '__main__':
        run()
  3. jklymak commented on Apr 9, 2021

    @jklymak
    Member

    It is pretty hard to see how #19703 could have caused any downstream issues since it doesn't change anything user facing, except to add a new style.

    I'm not convinced this is Matplotlib's issue:

    import matplotlib.pyplot as plt
    import numpy as np
    
    ax = plt.subplot(1, 1, 1, projection='polar')
    ax.imshow(np.zeros((100, 200)))
    
    plt.savefig('test.png')

    works fine on master.

  4. pllim commented on Apr 9, 2021

    @pllim
    Author

    Indeed, I couldn't reproduce this if I take out the astropy stuff and seems to only affect contours. I'll have to defer to the expertise of @astrofrog and @Cadair here.

  5. jklymak commented on Apr 9, 2021

    @jklymak
    Member

    I'm going to close for now because this has gotten a bit confusing, but feel free to open a new issue if you narrow it down to something we broke. Thanks again for testing us early on!

  6. tacaswell commented on Apr 9, 2021

    @tacaswell
    Member

    E AttributeError: 'NoneType' object has no attribute 'dpi'

    The issue is not that figure.dpi has gone away, the issue is that self.figure is None

  7. jklymak commented on Apr 9, 2021

    @jklymak
    Member

    Is this possibly the add_axes issue? #19496, #18364? and somehow this axes is not being added to the figure?

  8. pllim commented on Apr 10, 2021

    @pllim
    Author

    I think I did the bisect wrong. It gives me different answer depending on where I set the "good". I can't seem to find an option that is equivalent to -m 1 for cherry-pick.

    The only thing I am sure of is that this is caused by something that got merged in the past 24-36 hours (as of writing). Let's just wait for Tom Robitaille and Stuart Mumford's inputs. I don't usually work with that part of the code, and I need to move on to other work. Thanks, everyone!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions