Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error when using path effect with a PolyCollection #20991

Closed
jvierstra opened this issue Sep 4, 2021 · 2 comments · Fixed by #22417
Closed

[Bug]: Error when using path effect with a PolyCollection #20991

jvierstra opened this issue Sep 4, 2021 · 2 comments · Fixed by #22417
Milestone

Comments

@jvierstra
Copy link

jvierstra commented Sep 4, 2021

Bug summary

When trying to add a shadow to a "fill_between", I get the following error: "
SystemError: new style getargs format but argument is not a tuple"

I fixed it by changing the following code in "patheffects.py"

Lines: 100

 def draw_path(self, gc, tpath, affine, rgbFace=None):
        if rgbFace is not None:
            rgbFace = tuple(rgbFace)
        for path_effect in self._path_effects:
            path_effect.draw_path(self._renderer, gc, tpath, affine, rgbFace)

Code for reproduction

import matplotlib.pyplot as plt
import numpy as npimport matplotlib.patheffects as mpatheffects

x = np.arange(100)
y = x.copy()

p = plt.fill_between(x, 0, y)
p.set_path_effects([mpatheffects.withSimplePatchShadow()])

Actual outcome

/home/jvierstra/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/seaborn/categorical.py:1296: UserWarning: 59.2% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.
  warnings.warn(msg, UserWarning)
/home/jvierstra/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/seaborn/categorical.py:1296: UserWarning: 41.7% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.
  warnings.warn(msg, UserWarning)
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
~/.local/lib/python3.9/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/.local/lib/python3.9/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
    250         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    251     if 'retina' in formats or 'png2x' in formats:
--> 252         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
    253     if 'jpg' in formats or 'jpeg' in formats:
    254         jpg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'jpg', **kwargs))

~/.local/lib/python3.9/site-packages/IPython/core/pylabtools.py in retina_figure(fig, **kwargs)
    140 def retina_figure(fig, **kwargs):
    141     """format a figure as a pixel-doubled (retina) PNG"""
--> 142     pngdata = print_figure(fig, fmt='retina', **kwargs)
    143     # Make sure that retina_figure acts just like print_figure and returns
    144     # None when the figure is empty.

~/.local/lib/python3.9/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    132         FigureCanvasBase(fig)
    133 
--> 134     fig.canvas.print_figure(bytes_io, **kw)
    135     data = bytes_io.getvalue()
    136     if fmt == 'svg':

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2253                 # force the figure dpi to 72), so we need to set it again here.
   2254                 with cbook._setattr_cm(self.figure, dpi=dpi):
-> 2255                     result = print_method(
   2256                         filename,
   2257                         facecolor=facecolor,

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1667             kwargs.pop(arg)
   1668 
-> 1669         return func(*args, **kwargs)
   1670 
   1671     return wrapper

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    506             *metadata*, including the default 'Software' key.
    507         """
--> 508         FigureCanvasAgg.draw(self)
    509         mpl.image.imsave(
    510             filename_or_obj, self.buffer_rgba(), format="png", origin="upper",

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    404              (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
    405               else nullcontext()):
--> 406             self.figure.draw(self.renderer)
    407             # A GUI class may be need to update a window using this draw, so
    408             # don't forget to call the superclass.

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     72     @wraps(draw)
     73     def draw_wrapper(artist, renderer, *args, **kwargs):
---> 74         result = draw(artist, renderer, *args, **kwargs)
     75         if renderer._rasterizing:
     76             renderer.stop_rasterizing()

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/figure.py in draw(self, renderer)
   2788 
   2789             self.patch.draw(renderer)
-> 2790             mimage._draw_list_compositing_images(
   2791                 renderer, self, artists, self.suppressComposite)
   2792 

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130     if not_composite or not has_images:
    131         for a in artists:
--> 132             a.draw(renderer)
    133     else:
    134         # Composite any adjacent images together

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)
    429                          else deprecation_addendum,
    430                 **kwargs)
--> 431         return func(*inner_args, **inner_kwargs)
    432 
    433     return wrapper

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2919             renderer.stop_rasterizing()
   2920 
-> 2921         mimage._draw_list_compositing_images(renderer, self, artists)
   2922 
   2923         renderer.close_group('axes')

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130     if not_composite or not has_images:
    131         for a in artists:
--> 132             a.draw(renderer)
    133     else:
    134         # Composite any adjacent images together

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/collections.py in draw(self, renderer)
   1010     def draw(self, renderer):
   1011         self.set_sizes(self._sizes, self.figure.dpi)
-> 1012         super().draw(renderer)
   1013 
   1014 

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/collections.py in draw(self, renderer)
    408                 mpath.Path(offsets), transOffset, tuple(facecolors[0]))
    409         else:
--> 410             renderer.draw_path_collection(
    411                 gc, transform.frozen(), paths,
    412                 self.get_transforms(), offsets, transOffset,

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/patheffects.py in draw_path_collection(self, gc, master_transform, paths, *args, **kwargs)
    128             # Call the base path effect function - this uses the unoptimised
    129             # approach of calling "draw_path" multiple times.
--> 130             return super().draw_path_collection(gc, master_transform, paths,
    131                                                 *args, **kwargs)
    132 

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/backend_bases.py in draw_path_collection(self, gc, master_transform, paths, all_transforms, offsets, offsetTrans, facecolors, edgecolors, linewidths, linestyles, antialiaseds, urls, offset_position)
    261                 transform = transform.frozen()
    262                 transform.translate(xo, yo)
--> 263             self.draw_path(gc0, path, transform, rgbFace)
    264 
    265     def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/patheffects.py in draw_path(self, gc, tpath, affine, rgbFace)
     99     def draw_path(self, gc, tpath, affine, rgbFace=None):
    100         for path_effect in self._path_effects:
--> 101             path_effect.draw_path(self._renderer, gc, tpath, affine,
    102                                   rgbFace)
    103 

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/patheffects.py in draw_path(self, renderer, gc, tpath, affine, rgbFace)
    170     class withEffect(effect_class):
    171         def draw_path(self, renderer, gc, tpath, affine, rgbFace):
--> 172             super().draw_path(renderer, gc, tpath, affine, rgbFace)
    173             renderer.draw_path(gc, tpath, affine, rgbFace)
    174 

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/patheffects.py in draw_path(self, renderer, gc, tpath, affine, rgbFace)
    210         gc0.copy_properties(gc)
    211         gc0 = self._update_gc(gc0, self._gc)
--> 212         #renderer.draw_path(
    213         #    gc0, tpath, affine + self._offset_transform(renderer), rgbFace)
    214         gc0.restore()

~/.local/miniconda3/envs/py3.9_default/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py in draw_path(self, gc, path, transform, rgbFace)
    159         else:
    160             try:
--> 161                 self._renderer.draw_path(gc, path, transform, rgbFace)
    162             except OverflowError as err:
    163                 raise OverflowError("Exceeded cell block limit (set "

SystemError: new style getargs format but argument is not a tuple

Expected outcome

The code to run without error.

Operating system

Linux/CentOS

Matplotlib Version

3.4.3

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.9

Jupyter version

No response

Other libraries

No response

Installation

pip

Conda channel

No response

@QuLogic
Copy link
Member

QuLogic commented Sep 4, 2021

That seems reasonable; would you like to open a PR with that change?

@anntzer
Copy link
Contributor

anntzer commented Sep 4, 2021

Actually I think the "correct" fix is e.g. #19563 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants