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: show_geometry() errors on matplotlib 3.5.1 #1097

Closed
WYVERN2742 opened this issue Dec 15, 2021 · 3 comments · Fixed by #1110
Closed

Bug: show_geometry() errors on matplotlib 3.5.1 #1097

WYVERN2742 opened this issue Dec 15, 2021 · 3 comments · Fixed by #1110
Labels
bug Something isn't working

Comments

@WYVERN2742
Copy link

Updating to matplotlib 3.5.1 causes show_geometry to fail.

Fix should be as simple as changing _Arrow3D class at https://github.com/TomographicImaging/CIL/blob/master/Wrappers/Python/cil/utilities/display.py#L393 to have the do_3d_projection function:

class _Arrow3D(FancyArrowPatch):

	def __init__(self, xs, ys, zs, *args, **kwargs):
		FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
		self._verts3d = xs, ys, zs

	def draw(self, renderer):
		xs3d, ys3d, zs3d = self._verts3d
		xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M)
		self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
		FancyArrowPatch.draw(self, renderer)

	def do_3d_projection(self, renderer=None):
		xs3d, ys3d, zs3d = self._verts3d
		xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M)
		self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))

Reproduction Steps:

  1. Install CIL with latest matplotlib (3.5.1)

  2. Run 00_CIL_geometry.ipynb from CIL-Demos

    from cil.framework import AcquisitionGeometry
    from cil.utilities.display import show_geometry
    
    ag = AcquisitionGeometry.create_Parallel2D(detector_position=[0,10])\
    	.set_panel(num_pixels=10)\
    	.set_angles(angles=range(0,180))
    
    show_geometry(ag)
  3. Geometry fails

Python Error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\mambaforge\envs\cil\lib\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)

~\mambaforge\envs\cil\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
	149         FigureCanvasBase(fig)
	150 
--> 151     fig.canvas.print_figure(bytes_io, **kw)
	152     data = bytes_io.getvalue()
	153     if fmt == 'svg':

~\mambaforge\envs\cil\lib\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)
   2293                 )
   2294                 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2295                     self.figure.draw(renderer)
   2296 
   2297             if bbox_inches:

~\mambaforge\envs\cil\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
	 71     @wraps(draw)
	 72     def draw_wrapper(artist, renderer, *args, **kwargs):
---> 73         result = draw(artist, renderer, *args, **kwargs)
	 74         if renderer._rasterizing:
	 75             renderer.stop_rasterizing()

~\mambaforge\envs\cil\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer)
	 48                 renderer.start_filter()
	 49 
---> 50             return draw(artist, renderer)
	 51         finally:
	 52             if artist.get_agg_filter() is not None:

~\mambaforge\envs\cil\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
   2808 
   2809             self.patch.draw(renderer)
-> 2810             mimage._draw_list_compositing_images(
   2811                 renderer, self, artists, self.suppressComposite)
   2812 

~\mambaforge\envs\cil\lib\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

~\mambaforge\envs\cil\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer)
	 48                 renderer.start_filter()
	 49 
---> 50             return draw(artist, renderer)
	 51         finally:
	 52             if artist.get_agg_filter() is not None:

~\mambaforge\envs\cil\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in draw(self, renderer)
	449                                     for axis in self._get_axis_list()) + 1
	450                 collection_zorder = patch_zorder = zorder_offset
--> 451                 for artist in sorted(collections_and_patches,
	452                                      key=do_3d_projection,
	453                                      reverse=True):

~\mambaforge\envs\cil\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in do_3d_projection(artist)
	424                 """
	425                 try:
--> 426                     signature = inspect.signature(artist.do_3d_projection)
	427                     signature.bind()
	428                 # ValueError if `inspect.signature` cannot provide a signature

AttributeError: '_Arrow3D' object has no attribute 'do_3d_projection'
@paskino paskino added the bug Something isn't working label Dec 16, 2021
@epapoutsellis
Copy link
Contributor

Thank you @WYVERN2742 , we changed our installation instructions to force matplotlib=3.4.3 version.

@tacaswell
Copy link

You can drop the draw method altogether.

This was referenced Jan 6, 2022
@gfardell
Copy link
Member

gfardell commented Jan 6, 2022

Thank you @WYVERN2742

I've updated our conda-recipe and will tag and release a new version today (cil v21.3.1). I've opened an enhancement request #1111 to address the deprecated functions when we upgrade to newer matplotlib versions.

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.

5 participants