Trouble saving graphics

76 views
Skip to first unread message

Ed Scheinerman

unread,
Sep 7, 2013, 9:06:59 AM9/7/13
to sage-s...@googlegroups.com
I'm using Sage 5.11 on a Mac

I've been used to creating graphs and then saving them as PDF's for inclusion in papers. Using code like this:

sage: g = graphs.PetersenGraph()
sage: pic = g.plot()
sage: pic.save('pete.pdf')

But now it just throws a bunch of errors:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-56-d63f9d409a56> in <module>()
----> 1 pic.save('pete.pdf')

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/sage/misc/decorators.pyc in wrapper(*args, **kwds)
    456             kwds[self.name + "options"] = suboptions
    457 
--> 458             return func(*args, **kwds)
    459 
    460         #Add the options specified by @options to the signature of the wrapped

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/sage/plot/graphics.pyc in save(self, filename, **kwds)
   2753                 figure.savefig(filename, dpi=dpi, bbox_inches='tight',
   2754                     bbox_extra_artists=self._bbox_extra_artists,
-> 2755                     transparent=transparent)
   2756             else:
   2757                 figure.savefig(filename, dpi=dpi,

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/figure.pyc in savefig(self, *args, **kwargs)
   1368             kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
   1369 
-> 1370         self.canvas.print_figure(*args, **kwargs)
   1371 
   1372         if transparent:

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2053                     orientation=orientation,
   2054                     dryrun=True,
-> 2055                     **kwargs)
   2056                 renderer = self.figure._cachedRenderer
   2057                 bbox_inches = self.figure.get_tightbbox(renderer)

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_pdf(self, *args, **kwargs)
   1846         from backends.backend_pdf import FigureCanvasPdf # lazy import
   1847         pdf = self.switch_backends(FigureCanvasPdf)
-> 1848         return pdf.print_pdf(*args, **kwargs)
   1849 
   1850     def print_pgf(self, *args, **kwargs):

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.py in print_pdf(self, filename, **kwargs)
   2299                                          width, height, image_dpi, RendererPdf(file, image_dpi),
   2300                                          bbox_inches_restore=_bbox_inches_restore)
-> 2301             self.figure.draw(renderer)
   2302             renderer.finalize()
   2303         finally:

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52     def draw_wrapper(artist, renderer, *args, **kwargs):
     53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
     55         after(artist, renderer)
     56 

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
   1004         dsu.sort(key=itemgetter(0))
   1005         for zorder, a, func, args in dsu:
-> 1006             func(*args)
   1007 
   1008         renderer.close_group('figure')

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52     def draw_wrapper(artist, renderer, *args, **kwargs):
     53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
     55         after(artist, renderer)
     56 

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/axes.pyc in draw(self, renderer, inframe)
   2084 
   2085         for zorder, a in dsu:
-> 2086             a.draw(renderer)
   2087 
   2088         renderer.close_group('axes')

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52     def draw_wrapper(artist, renderer, *args, **kwargs):
     53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
     55         after(artist, renderer)
     56 

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/collections.pyc in draw(self, renderer)
    693                     (np.sqrt(x) * self.figure.dpi / 72.0))
    694                 for x in self._sizes]
--> 695         return Collection.draw(self, renderer)
    696 
    697 class PolyCollection(Collection):

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52     def draw_wrapper(artist, renderer, *args, **kwargs):
     53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
     55         after(artist, renderer)
     56 

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/collections.pyc in draw(self, renderer)
    257             offsets, transOffset, self.get_facecolor(), self.get_edgecolor(),
    258             self._linewidths, self._linestyles, self._antialiaseds, self._urls,
--> 259             self._offset_position)
    260 
    261         gc.restore()

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.py in draw_path_collection(self, gc, master_transform, paths, all_transforms, offsets, offsetTrans, facecolors, edgecolors, linewidths, linestyles, antialiaseds, urls, offset_position)
   1546             output(1, 0, 0, 1, dx, dy, Op.concat_matrix, path_id, Op.use_xobject)
   1547             lastx, lasty = xo, yo
-> 1548         output(*self.gc.pop())
   1549 
   1550     def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):

/Users/ers/share/sage-5.11/local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.py in pop(self)
   2091 
   2092     def pop(self):
-> 2093         assert self.parent is not None
   2094         self.copy_properties(self.parent)
   2095         self.parent = self.parent.parent

AssertionError: 

P Purkayastha

unread,
Sep 7, 2013, 12:01:40 PM9/7/13
to sage-s...@googlegroups.com
It seems saving to pdf is broken on sage-5.10 onwards. Works till
sage-5.9. The problem is only in graphs. Normal plots work fine.

I have opened http://trac.sagemath.org/ticket/15173 to track this.
> --
> You received this message because you are subscribed to the Google
> Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.


Ed Scheinerman

unread,
Sep 7, 2013, 9:22:42 PM9/7/13
to sage-s...@googlegroups.com
I found a temporary workaround. Save as .eps (which works fine) and then use epstopdf to convert to .pdf. 

Nathann Cohen

unread,
Sep 8, 2013, 9:07:35 AM9/8/13
to sage-s...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages