basemap Cairo exception

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 Stapleton

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

···

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

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 doing
zoomed in ortho maps? Am I doing something wrong?

(actually hit reply all this time)

Alex Stapleton wrote:

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

Alex Stapleton wrote:
    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.
    

I suppose it's not up to matplotlib to work around silly limits in
Cairo :slight_smile:

Slightly OT -- I put the check for the length of the path in there because otherwise pycairo/cairo segfaults, and I thought an exception would be preferable to a segfault. That limit was obtained through experimentation, and might not be accurate (I couldn't actually find a hard limit in the cairo code, it's more likely due to an interaction of multiple parts of the code). This was all true with Cairo 1.4.10/pycairo 1.4.0. With other versions this may not be the case, but my "catch" happens regardless. We may want to revisit that if we discover that newer versions of Cairo can handle longer paths.

Cheers,
Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA