TyberiusPrime · GitHub

Minimal Example

import pandas as pd
import plotnine
df = pd.DataFrame(patsy.demo_data("a",'b','x','y', 'z'))
p = plotnine.ggplot(df)
p += plotnine.geom_point(plotnine.aes('x','y'))
p += plotnine.facet_wrap('b')
p += plotnine.theme_xkcd()
p.save('test.png') # succeeds
p.save('test2.png', dpi=72) # fails

fails with the following stack trace:

/martha/ffs/e/plotnine_exploration/code3/plotnine/plotnine/ggplot.py in save(self, filename, format, path, width, height, units, dpi, limitsize, verbose, **kwargs)
    726         except Exception as err:
    727             figure[0] and plt.close(figure[0])
--> 728             raise err
    729         else:
    730             figure[0] and plt.close(figure[0])
/martha/ffs/e/plotnine_exploration/code3/plotnine/plotnine/ggplot.py in save(self, filename, format, path, width, height, units, dpi, limitsize, verbose, **kwargs)
    723
    724         try:
--> 725             _save()
    726         except Exception as err:
    727             figure[0] and plt.close(figure[0])
/martha/ffs/e/plotnine_exploration/code3/plotnine/plotnine/ggplot.py in _save()
    720                 fig_kwargs['frameon'] = True
    721
--> 722             fig.savefig(filename, **fig_kwargs)
    723
    724         try:
/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py in savefig(self, fname, **kwargs)
   2033             self.set_frameon(frameon)
   2034
-> 2035         self.canvas.print_figure(fname, **kwargs)
   2036
   2037         if frameon:
/usr/local/lib/python3.6/dist-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2210                     orientation=orientation,
   2211                     dryrun=True,
-> 2212                     **kwargs)
   2213                 renderer = self.figure._cachedRenderer
   2214                 bbox_inches = self.figure.get_tightbbox(renderer)
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    511
    512     def print_png(self, filename_or_obj, *args, **kwargs):
--> 513         FigureCanvasAgg.draw(self)
    514         renderer = self.get_renderer()
    515         original_dpi = renderer.dpi
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_agg.py in draw(self)
    431             # if toolbar:
    432             #     toolbar.set_cursor(cursors.WAIT)
--> 433             self.figure.draw(self.renderer)
    434             # A GUI class may be need to update a window using this draw, so
    435             # don't forget to call the superclass.
/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:
/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py in draw(self, renderer)
   1470
   1471             if self.frameon:
-> 1472                 self.patch.draw(renderer)
   1473
   1474             mimage._draw_list_compositing_images(
/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:
/usr/local/lib/python3.6/dist-packages/matplotlib/patches.py in draw(self, renderer)
    556             renderer = PathEffectRenderer(self.get_path_effects(), renderer)
    557
--> 558         renderer.draw_path(gc, tpath, affine, rgbFace)
    559
    560         gc.restore()
/usr/local/lib/python3.6/dist-packages/matplotlib/patheffects.py in draw_path(self, gc, tpath, affine, rgbFace)
    108         for path_effect in self._path_effects:
    109             path_effect.draw_path(self._renderer, gc, tpath, affine,
--> 110                                   rgbFace)
    111
    112     def draw_markers(self, gc, marker_path, marker_trans, path, *args,
/usr/local/lib/python3.6/dist-packages/matplotlib/patheffects.py in draw_path(self, renderer, gc, tpath, affine, rgbFace)
    209     """
    210     def draw_path(self, renderer, gc, tpath, affine, rgbFace):
--> 211         Stroke.draw_path(self, renderer, gc, tpath, affine, rgbFace)
    212         renderer.draw_path(gc, tpath, affine, rgbFace)
    213
/usr/local/lib/python3.6/dist-packages/matplotlib/patheffects.py in draw_path(self, renderer, gc, tpath, affine, rgbFace)
    196         gc0.copy_properties(gc)
    197
--> 198         gc0 = self._update_gc(gc0, self._gc)
    199         trans = self._offset_transform(renderer, affine)
    200         renderer.draw_path(gc0, tpath, trans, rgbFace)
AttributeError: 'withStroke' object has no attribute '_gc'

Read the original on github.com ↗