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)
ax = plt.subplot(111, projection = 'mollweide')
Some of the points seem to be wrongly drawn (See Figure below).
The same code used without projection outputs a perfectly normal map:
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 ]
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)?
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.
@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.
@dmcdougall: I think the answer to your question is "would be nice", but not under the current implementation.
This seems to have gotten worse: