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

Pylab contourf plot using Mollweide projection create artefacts #1910

Closed
ghost opened this issue Apr 16, 2013 · 9 comments
Closed

Pylab contourf plot using Mollweide projection create artefacts #1910

ghost opened this issue Apr 16, 2013 · 9 comments

Comments

@ghost
Copy link

ghost commented Apr 16, 2013

matplotlib 1.1.1rc, python 2.7.3, Ubuntu 12.04 LTS

pylab.contourf create artefacts when used in a Mollweide projection.

Here is an example code:

import numpy as np
import pylab as plt

ra = np.linspace(-np.pi, np.pi, 40)
dec= np.linspace(-np.pi/2, np.pi/2, 20)
X,Y = np.meshgrid(ra,dec)
Z = np.sin(X) * np.cos(X) * np.sin(Y) * np.cos(Y)

plt.figure()
ax = plt.subplot(111, projection = 'mollweide')
ax.contourf(X,Y,Z,100)
ax.contour(X,Y,Z,10,colors='k')

plt.show()

Some of the points seem to be wrongly drawn (See Figure below).
mollweide
The same code used without projection outputs a perfectly normal map:
normal

You may have noticed that the contour lines work in both images. The artefacts seem to be always at the same place.

[Originally posted on Stackoverflow: http://stackoverflow.com/questions/16018243/pylab-contour-plot-using-mollweide-projection-create-artefacts ]

@pelson
Copy link
Member

pelson commented Apr 16, 2013

The strip in the image suggests that there has been a polygon which has transformed badly. I'm 95% confident that this is because of your X limits are +/- Pi which are both singularities on the Mollweide projection.

Indeed, when I run your code (v1.3-dev), I get the following warning:

lib/matplotlib/projections/geo.py:484: RuntimeWarning: invalid value encountered in arcsin
  theta = np.arcsin(y / np.sqrt(2))

I've tried fiddling with the extents of the underlying data, but without much luck.

Have you considered using one of the mapping toolkits (Basemap or cartopy)?

@ghost
Copy link
Author

ghost commented Apr 16, 2013

I tried to restrict the range of the of X,Y. It does work for up to 99% of their boundary value. With 99.5% of (-pi/2, pi/2) and (-pi, pi) it shows even more artefacts.

The same code using Basemap works perfectly.

@dmcdougall
Copy link
Member

@pelson Should the contouring code expect to handle post-contouring transforms to the data space? I think this is going to be a tough nut to crack.

@mdboom
Copy link
Member

mdboom commented Jun 17, 2013

@dmcdougall: I think the answer to your question is "would be nice", but not under the current implementation.

@tacaswell tacaswell added this to the v1.5.x milestone Aug 17, 2014
@tacaswell
Copy link
Member

This seems to have gotten worse:

test image

@WeatherGod
Copy link
Member

This kinda looks like the polygon closing issue we fixed back in July for
mplot3d...

On Wed, Nov 26, 2014 at 3:11 PM, Thomas A Caswell notifications@github.com
wrote:

This seems to have gotten worse:

[image: test image]
https://cloud.githubusercontent.com/assets/199813/5208050/2c5c15ba-757e-11e4-9265-f9d680fc242c.png


Reply to this email directly or view it on GitHub
#1910 (comment)
.

@dstansby
Copy link
Member

Looks a bit better now! This is on 2.0.0b4+2949.gf12abca

figure_1

@tacaswell
Copy link
Member

Fixed as far back as 1.5.0!

Might be interesting to track down when this was fixed (git bisect is fun!), but closing.

@tacaswell
Copy link
Member

so

import numpy as np
import matplotlib.pyplot as plt
import matplotlib

plt.ion()

ra = np.linspace(-np.pi, np.pi, 40)
dec= np.linspace(-np.pi/2, np.pi/2, 20)
X,Y = np.meshgrid(ra,dec)
Z = np.sin(X) * np.cos(X) * np.sin(Y) * np.cos(Y)

plt.figure()
ax = plt.subplot(111, projection = 'mollweide')
ax.contourf(X,Y,Z,100)
ax.contour(X,Y,Z,10,colors='k')
ax.set_title(matplotlib.__version__)
plt.show()

@QuLogic QuLogic modified the milestones: v1.5.0, 2.1 (next point release) Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants