basemap Cairo exception

Alex Stapleton wrote:

2008/7/16 Jeff Whitaker <jswhit@...146...>:
  

Alex Stapleton wrote:
    

Not sure if this is the right place to send this, can't seem to find a
dedicated bugs list or issue tracker. Or much discussion regarding the
basemap toolkit at all really.

Trying to savefig some Basemap instances causes the following
exception in the Cairo backend. Seems to work alright using the Agg
backend but the fill doesn't seem to come out properly. The sea gets
colored as well as the continents.

Traceback (most recent call last):
File "map.py", line 48, in <module>
   plt.savefig("map.png", dpi=100)
File "/usr/lib/python2.5/site-packages/matplotlib/pyplot.py", line
286, in savefig
   return fig.savefig(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/matplotlib/figure.py", line
1033, in savefig
   self.canvas.print_figure(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py",
line 1301, in print_figure
   **kwargs)
File
"/usr/lib/python2.5/site-packages/matplotlib/backends/backend_cairo.py",
line 406, in print_png
   self.figure.draw (renderer)
File "/usr/lib/python2.5/site-packages/matplotlib/figure.py", line
833, in draw
   for a in self.axes: a.draw(renderer)
File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 1539, in
draw
   a.draw(renderer)
File "/usr/lib/python2.5/site-packages/matplotlib/patches.py", line
285, in draw
   renderer.draw_path(gc, tpath, affine, rgbFace)
File
"/usr/lib/python2.5/site-packages/matplotlib/backends/backend_cairo.py",
line 140, in draw_path
   raise ValueError("The Cairo backend can not draw paths longer than
18980 points.")
ValueError: The Cairo backend can not draw paths longer than 18980 points.

Here's a short reduction

import matplotlib
matplotlib.use("Cairo")
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

map = Basemap(projection='ortho',
             llcrnrlon=-12.7, llcrnrlat=49,
             urcrnrlon=4.7, urcrnrlat=61,
             lat_0 = 50, lon_0 = 0,
             lat_ts=50,
             resolution='i')
map.drawcoastlines(linewidth=0.5)
map.drawcountries(linewidth=0.5)
map.drawstates(linewidth=0.5)
map.drawmapboundary()
plt.savefig("map.png", dpi=100)

Alex: I don't have the Cairo backend installed, but I bet it would work if
you changed resolution='i' to resolution='l'. Seems like a pretty severe
limitation of the backend though.

-Jeff
    
I suppose it's not up to matplotlib to work around silly limits in
Cairo :slight_smile: What about the fill issue with the Agg backend when doingfil
zoomed in ortho maps? Am I doing something wrong?
  

Alex: I see in the example you sent that the whole map gets filled when the fillcontinents method is used. Is this what you mean? There's a KNOWN_BUGS file with this entry:

* The fillcontinents method doesn't always do the right thing. Matplotlib
always tries to fill the inside of a polygon. Under certain situations,
what is the inside of a coastline polygon can be ambiguous, and the
outside may be filled instead of the inside. To trigger this,
run the garp.py example with lon=-71,lat=-33 (Santiago, Chile).
Workaround - mask the land areas with the drawlsmask method instead of
filling the coastline polygons.

Using the orthographic projection to plot a local region is probably not the best idea though - it's really intended for the global domain to mimic what a satellite would see. I'd try the transverse mercator ('tmerc' - as in the highres.py example), or lambert conformal ('lcc') instead. The fillcontinents method does the right thing in both cases with your map region.

BTW: lat_ts doesn't do anything for projection='ortho'.

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
325 Broadway Boulder, CO, USA 80305-3328