Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lpsinger opened this issue Jan 21, 2017 · 7 comments
Closed

Comments

@lpsinger
Copy link
Contributor

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
@efiring
Copy link
Member

efiring commented Jan 23, 2017

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?

@lpsinger
Copy link
Contributor Author

Yes.

@efiring
Copy link
Member

efiring commented Jan 23, 2017

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?

@lpsinger
Copy link
Contributor Author

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

@WeatherGod
Copy link
Member

WeatherGod commented Jan 23, 2017 via email

@lpsinger
Copy link
Contributor Author

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

skymoo pushed a commit to lscsoft/lalsuite-archive that referenced this issue Jan 23, 2017
There was a change in the behavior of `Axes.imshow()` on non-affine
axes. See also <matplotlib/matplotlib#7903>.
skymoo pushed a commit to lscsoft/lalsuite-archive that referenced this issue Jan 24, 2017
There was a change in the behavior of `Axes.imshow()` on non-affine
axes. See also <matplotlib/matplotlib#7903>.
@lpsinger
Copy link
Contributor Author

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.

@lpsinger lpsinger closed this as completed Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants