Skip to content

Regression: imshow on geo axes produces an empty plot in matplotlib 2.0.0 #7903

Closed

Description

@lpsinger

Bug summary

In Matplotlib 1.5.3, it was possible to use imshow on geo axes (e.g. the mollweide projection defined in matplotlib.projections.geo. In Matplotlib 2.0.0, this produces a blank plot.

Code for reproduction

Here is an example that worked in 1.5.3.

from matplotlib import pyplot as plt
import numpy as np

lon = np.linspace(-np.pi, np.pi)
lat = np.linspace(-np.pi/2, np.pi/2)
lon, lat = np.meshgrid(lon, lat)

ax = plt.axes(projection='mollweide')
ax.grid()
ax.imshow(lon, extent=[-np.pi, np.pi, -np.pi/2, np.pi/2], aspect=ax.get_aspect())
plt.savefig('test.png')

Actual outcome

This is the output on Matplotlib 2.0.0: blank axes.
test-2 0 0

Expected outcome

This was the output in Matplotlib 1.5.3.
test-1 5 3

Matplotlib version

Installed from MacPorts on OS X 10.11.6 "El Capitan". Port versions:

  • py27-matplotlib @1.5.3_0+cairo
  • py27-matplotlib @2.0.0_0+cairo

Activity

  1. efiring commented on Jan 23, 2017

    @efiring
    Member

    It appears that in 1.5.3 the image was being created in Cartesian coordinates and then clipped to the projection. Is this what you want?

  2. lpsinger commented on Jan 23, 2017

    @lpsinger
    ContributorAuthor

    Yes.

  3. efiring commented on Jan 23, 2017

    @efiring
    Member

    That seems like fundamentally incorrect behavior, doesn't it? Wouldn't most users expect that if anything, imshow with a projection would warp the image to that projection? It's never done that, though. In 2.0 its behavior with a log scale on one or both axes has changed so that it does map the image to the scale, but I think that its behavior with a non-affine projection has always been undefined. If so, it should raise an error. Alternatively, I suppose it could warn and drop back to the 1.5.x behavior. Comments, @mdboom?

  4. lpsinger commented on Jan 23, 2017

    @lpsinger
    ContributorAuthor

    I was looking through past PRs... did this change occur in #5718?

  5. WeatherGod commented on Jan 23, 2017

    @WeatherGod
    Member
  6. lpsinger commented on Jan 23, 2017

    @lpsinger
    ContributorAuthor

    Oh, OK! I modified my test code to use ax.imshow(..., extent=[0, 1, 0, 1], transform=ax.transAxes):

    #!/usr/bin/env python
    from matplotlib import pyplot as plt
    import numpy as np
    
    lon = np.linspace(-np.pi, np.pi)
    lat = np.linspace(-np.pi/2, np.pi/2)
    lon, lat = np.meshgrid(lon, lat)
    
    ax = plt.axes(projection='mollweide')
    ax.grid()
    ax.imshow(lon, extent=[0, 1, 0, 1], aspect=ax.get_aspect(), transform=ax.transAxes)
    plt.savefig('test.png')

    And it works now:

    test

  7. lpsinger commented on Jan 24, 2017

    @lpsinger
    ContributorAuthor

    Oh, OK! I modified my test code to use ax.imshow(..., extent=[0, 1, 0, 1], transform=ax.transAxes):

    Was this just a latent bug in my own code that was revealed by the transition to 2.0.0? If so, then we can close this issue.

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