Skip to content

Instantly share code, notes, and snippets.

@JohnAtl
Created June 11, 2022 19:19
Show Gist options
  • Save JohnAtl/74be42e7739aa73cdf74e2ed7b4298b6 to your computer and use it in GitHub Desktop.
Save JohnAtl/74be42e7739aa73cdf74e2ed7b4298b6 to your computer and use it in GitHub Desktop.
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Input In [221], in <cell line: 6>()
4 display = plot_anat(mni_img, figure=fig, display_mode='z', cut_coords=z_coords)
5 display.add_markers(coords, figure=fig)
----> 6 display.savefig(f'/output/2ndLevel/{cont_name}/task-ao/cluster_z_slices.png')
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/nilearn/plotting/displays/_slicers.py:709, in BaseSlicer.savefig(self, filename, dpi)
696 """Save the figure to a file.
697
698 Parameters
(...)
706 Default=None.
707 """
708 facecolor = edgecolor = 'k' if self._black_bg else 'w'
--> 709 self.frame_axes.figure.savefig(filename, dpi=dpi,
710 facecolor=facecolor,
711 edgecolor=edgecolor)
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/figure.py:3019, in Figure.savefig(self, fname, transparent, **kwargs)
3015 for ax in self.axes:
3016 stack.enter_context(
3017 ax.patch._cm_set(facecolor='none', edgecolor='none'))
-> 3019 self.canvas.print_figure(fname, **kwargs)
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/backend_bases.py:2319, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2315 try:
2316 # _get_renderer may change the figure dpi (as vector formats
2317 # force the figure dpi to 72), so we need to set it again here.
2318 with cbook._setattr_cm(self.figure, dpi=dpi):
-> 2319 result = print_method(
2320 filename,
2321 facecolor=facecolor,
2322 edgecolor=edgecolor,
2323 orientation=orientation,
2324 bbox_inches_restore=_bbox_inches_restore,
2325 **kwargs)
2326 finally:
2327 if bbox_inches and restore_bbox:
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/backend_bases.py:1648, in _check_savefig_extra_args.<locals>.wrapper(*args, **kwargs)
1640 _api.warn_deprecated(
1641 '3.3', name=name, removal='3.6',
1642 message='%(name)s() got unexpected keyword argument "'
1643 + arg + '" which is no longer supported as of '
1644 '%(since)s and will become an error '
1645 '%(removal)s')
1646 kwargs.pop(arg)
-> 1648 return func(*args, **kwargs)
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/_api/deprecation.py:412, in delete_parameter.<locals>.wrapper(*inner_args, **inner_kwargs)
402 deprecation_addendum = (
403 f"If any parameter follows {name!r}, they should be passed as "
404 f"keyword, not positionally.")
405 warn_deprecated(
406 since,
407 name=repr(name),
(...)
410 else deprecation_addendum,
411 **kwargs)
--> 412 return func(*inner_args, **inner_kwargs)
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:540, in FigureCanvasAgg.print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
490 @_check_savefig_extra_args
491 @_api.delete_parameter("3.5", "args")
492 def print_png(self, filename_or_obj, *args,
493 metadata=None, pil_kwargs=None):
494 """
495 Write the figure to a PNG file.
496
(...)
538 *metadata*, including the default 'Software' key.
539 """
--> 540 FigureCanvasAgg.draw(self)
541 mpl.image.imsave(
542 filename_or_obj, self.buffer_rgba(), format="png", origin="upper",
543 dpi=self.figure.dpi, metadata=metadata, pil_kwargs=pil_kwargs)
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:436, in FigureCanvasAgg.draw(self)
432 # Acquire a lock on the shared font cache.
433 with RendererAgg.lock, \
434 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
435 else nullcontext()):
--> 436 self.figure.draw(self.renderer)
437 # A GUI class may be need to update a window using this draw, so
438 # don't forget to call the superclass.
439 super().draw()
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/artist.py:73, in _finalize_rasterization.<locals>.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()
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/artist.py:50, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
47 if artist.get_agg_filter() is not None:
48 renderer.start_filter()
---> 50 return draw(artist, renderer)
51 finally:
52 if artist.get_agg_filter() is not None:
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/figure.py:2796, in Figure.draw(self, renderer)
2793 if not self.get_visible():
2794 return
-> 2796 artists = self._get_draw_artists(renderer)
2798 try:
2799 renderer.open_group('figure', gid=self.get_gid())
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/figure.py:235, in FigureBase._get_draw_artists(self, renderer)
233 locator = ax.get_axes_locator()
234 if locator:
--> 235 pos = locator(ax, renderer)
236 ax.apply_aspect(pos)
237 else:
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/nilearn/plotting/displays/_slicers.py:1386, in BaseStackedSlicer._locator(self, axes, renderer)
1384 this_width = width_dict[display_ax.ax]
1385 left += this_width
-> 1386 return Bbox([[left_dict[axes], y0],
1387 [left_dict[axes] + width_dict[axes], y1]])
KeyError: <Axes:>
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/IPython/core/formatters.py:339, in BaseFormatter.__call__(self, obj)
337 pass
338 else:
--> 339 return printer(obj)
340 # Finally look for special method names
341 method = get_real_method(obj, self.print_method)
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/IPython/core/pylabtools.py:151, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
148 from matplotlib.backend_bases import FigureCanvasBase
149 FigureCanvasBase(fig)
--> 151 fig.canvas.print_figure(bytes_io, **kw)
152 data = bytes_io.getvalue()
153 if fmt == 'svg':
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/backend_bases.py:2295, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2289 renderer = _get_renderer(
2290 self.figure,
2291 functools.partial(
2292 print_method, orientation=orientation)
2293 )
2294 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2295 self.figure.draw(renderer)
2297 if bbox_inches:
2298 if bbox_inches == "tight":
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/artist.py:73, in _finalize_rasterization.<locals>.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()
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/artist.py:50, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
47 if artist.get_agg_filter() is not None:
48 renderer.start_filter()
---> 50 return draw(artist, renderer)
51 finally:
52 if artist.get_agg_filter() is not None:
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/figure.py:2796, in Figure.draw(self, renderer)
2793 if not self.get_visible():
2794 return
-> 2796 artists = self._get_draw_artists(renderer)
2798 try:
2799 renderer.open_group('figure', gid=self.get_gid())
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/matplotlib/figure.py:235, in FigureBase._get_draw_artists(self, renderer)
233 locator = ax.get_axes_locator()
234 if locator:
--> 235 pos = locator(ax, renderer)
236 ax.apply_aspect(pos)
237 else:
File /opt/miniconda-latest/envs/neuro/lib/python3.8/site-packages/nilearn/plotting/displays/_slicers.py:1386, in BaseStackedSlicer._locator(self, axes, renderer)
1384 this_width = width_dict[display_ax.ax]
1385 left += this_width
-> 1386 return Bbox([[left_dict[axes], y0],
1387 [left_dict[axes] + width_dict[axes], y1]])
KeyError: <Axes:>
<Figure size 4800x3600 with 5 Axes>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment