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

Our custom Arrow3D is not compatible with Matplotlib 3.6 #381

Closed
hakonanes opened this issue Sep 16, 2022 · 0 comments · Fixed by #382
Closed

Our custom Arrow3D is not compatible with Matplotlib 3.6 #381

hakonanes opened this issue Sep 16, 2022 · 0 comments · Fixed by #382
Labels
bug Something isn't working
Milestone

Comments

@hakonanes
Copy link
Member

Matplotlib 3.6 was just released, and this warning

>>> from orix.quaternion import Orientation
>>> fig = Orientation.identity().plot_unit_cell(return_figure=True)
>>> fig.savefig("test.png")
/tmp/ipykernel_8596/266685555.py:2: MatplotlibDeprecationWarning: The 'renderer' parameter of do_3d_projection() was deprecated in Matplotlib 3.4 and will be removed two minor releases later.
  fig.savefig("/home/hakon/test.png")

is now an error (shortened traceback only showing start and end):

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [2], in <cell line: 2>()
      1 fig = Orientation.identity().plot_unit_cell(return_figure=True)
----> 2 fig.savefig("/home/hakon/test.png")

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/figure.py:3272, in Figure.savefig(self, fname, transparent, **kwargs)
   3268     for ax in self.axes:
   3269         stack.enter_context(
   3270             ax.patch._cm_set(facecolor='none', edgecolor='none'))
-> 3272 self.canvas.print_figure(fname, **kwargs)

[...]

TypeError: draw() missing 1 required positional argument: 'renderer'

I discovered this from the failing test suite in #378.

I'll try to fix this before releasing v0.10.

Complete traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [2], in <cell line: 2>()
      1 fig = Orientation.identity().plot_unit_cell(return_figure=True)
----> 2 fig.savefig("/home/hakon/test.png")

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/figure.py:3272, in Figure.savefig(self, fname, transparent, **kwargs)
   3268     for ax in self.axes:
   3269         stack.enter_context(
   3270             ax.patch._cm_set(facecolor='none', edgecolor='none'))
-> 3272 self.canvas.print_figure(fname, **kwargs)

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/backend_bases.py:2338, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2334 try:
   2335     # _get_renderer may change the figure dpi (as vector formats
   2336     # force the figure dpi to 72), so we need to set it again here.
   2337     with cbook._setattr_cm(self.figure, dpi=dpi):
-> 2338         result = print_method(
   2339             filename,
   2340             facecolor=facecolor,
   2341             edgecolor=edgecolor,
   2342             orientation=orientation,
   2343             bbox_inches_restore=_bbox_inches_restore,
   2344             **kwargs)
   2345 finally:
   2346     if bbox_inches and restore_bbox:

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/backend_bases.py:2204, in FigureCanvasBase._switch_canvas_and_return_print_method.<locals>.<lambda>(*args, **kwargs)
   2200     optional_kws = {  # Passed by print_figure for other renderers.
   2201         "dpi", "facecolor", "edgecolor", "orientation",
   2202         "bbox_inches_restore"}
   2203     skip = optional_kws - {*inspect.signature(meth).parameters}
-> 2204     print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
   2205         *args, **{k: v for k, v in kwargs.items() if k not in skip}))
   2206 else:  # Let third-parties do as they see fit.
   2207     print_method = meth

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/_api/deprecation.py:410, in delete_parameter.<locals>.wrapper(*inner_args, **inner_kwargs)
    400     deprecation_addendum = (
    401         f"If any parameter follows {name!r}, they should be passed as "
    402         f"keyword, not positionally.")
    403     warn_deprecated(
    404         since,
    405         name=repr(name),
   (...)
    408                  else deprecation_addendum,
    409         **kwargs)
--> 410 return func(*inner_args, **inner_kwargs)

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:520, in FigureCanvasAgg.print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    471 @_api.delete_parameter("3.5", "args")
    472 def print_png(self, filename_or_obj, *args,
    473               metadata=None, pil_kwargs=None):
    474     """
    475     Write the figure to a PNG file.
    476 
   (...)
    518         *metadata*, including the default 'Software' key.
    519     """
--> 520     self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:466, in FigureCanvasAgg._print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata)
    461 def _print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata=None):
    462     """
    463     Draw the canvas, then save it using `.image.imsave` (to which
    464     *pil_kwargs* and *metadata* are forwarded).
    465     """
--> 466     FigureCanvasAgg.draw(self)
    467     mpl.image.imsave(
    468         filename_or_obj, self.buffer_rgba(), format=fmt, origin="upper",
    469         dpi=self.figure.dpi, metadata=metadata, pil_kwargs=pil_kwargs)

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:408, in FigureCanvasAgg.draw(self)
    404 # Acquire a lock on the shared font cache.
    405 with RendererAgg.lock, \
    406      (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
    407       else nullcontext()):
--> 408     self.figure.draw(self.renderer)
    409     # A GUI class may be need to update a window using this draw, so
    410     # don't forget to call the superclass.
    411     super().draw()

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/artist.py:74, in _finalize_rasterization.<locals>.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()

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/artist.py:51, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     48     if artist.get_agg_filter() is not None:
     49         renderer.start_filter()
---> 51     return draw(artist, renderer)
     52 finally:
     53     if artist.get_agg_filter() is not None:

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/figure.py:3069, in Figure.draw(self, renderer)
   3066         # ValueError can occur when resizing a window.
   3068 self.patch.draw(renderer)
-> 3069 mimage._draw_list_compositing_images(
   3070     renderer, self, artists, self.suppressComposite)
   3072 for sfig in self.subfigs:
   3073     sfig.draw(renderer)

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

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/matplotlib/artist.py:51, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     48     if artist.get_agg_filter() is not None:
     49         renderer.start_filter()
---> 51     return draw(artist, renderer)
     52 finally:
     53     if artist.get_agg_filter() is not None:

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/mpl_toolkits/mplot3d/axes3d.py:440, in Axes3D.draw(self, renderer)
    436 zorder_offset = max(axis.get_zorder()
    437                     for axis in self._axis_map.values()) + 1
    438 collection_zorder = patch_zorder = zorder_offset
--> 440 for artist in sorted(collections_and_patches,
    441                      key=lambda artist: artist.do_3d_projection(),
    442                      reverse=True):
    443     if isinstance(artist, mcoll.Collection):
    444         artist.zorder = collection_zorder

File ~/miniconda3/envs/orix-dev/lib/python3.9/site-packages/mpl_toolkits/mplot3d/axes3d.py:441, in Axes3D.draw.<locals>.<lambda>(artist)
    436 zorder_offset = max(axis.get_zorder()
    437                     for axis in self._axis_map.values()) + 1
    438 collection_zorder = patch_zorder = zorder_offset
    440 for artist in sorted(collections_and_patches,
--> 441                      key=lambda artist: artist.do_3d_projection(),
    442                      reverse=True):
    443     if isinstance(artist, mcoll.Collection):
    444         artist.zorder = collection_zorder

TypeError: draw() missing 1 required positional argument: 'renderer'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant