Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Pylab contourf plot using Mollweide projection create artefacts #1910

Open
jolfulorc opened this Issue · 6 comments

6 participants

@jolfulorc

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
Collaborator

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)?

@jolfulorc

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
Collaborator

@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
Owner

@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
@tacaswell
Owner

This seems to have gotten worse:

test image

@WeatherGod
Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.