Arguments are not passed to custom plotter
felixsc1 opened this issue · 1 comments
felixsc1 commented
As I see this (I might be wrong), when specifying the plotting_func the widget creates internally a new figure in any case, and passing then a custom figure handle as argument creates an error.
from niwidgets import NiftiWidget
import nilearn.plotting as nip
my_widget = NiftiWidget(img)
# my_widget.nifti_plotter(figsize=(10,20))
fig, axes = plt.subplots(1, 3, figsize=(5, 10))
my_widget.nifti_plotter(plotting_func=nip.plot_img, colormap=None, figsize=(5, 10),
figure=fig,
axes = axes)
The default case works fine, the img is shown as 3 axes and the figsize can be adjusted. To get more control over the figure and axes, I used the function call shown above but get the follow error message:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-92-a281499c2288> in <module>()
33 my_widget.nifti_plotter(plotting_func=nip.plot_img, colormap=None, figsize=(5, 10),
34 figure=fig,
---> 35 axes = axes
36 )
~/anaconda3/lib/python3.6/site-packages/niwidgets/niwidget_volume.py in nifti_plotter(self, plotting_func, colormap, figsize, **kwargs)
83 self._default_plotter(**kwargs)
84 else:
---> 85 self._custom_plotter(plotting_func, **kwargs)
86
87 def _default_plotter(self, mask_background=False, **kwargs):
~/anaconda3/lib/python3.6/site-packages/niwidgets/niwidget_volume.py in _custom_plotter(self, plotting_func, **kwargs)
241
242 # Create the widget:
--> 243 interact(self._custom_plot_wrapper, data=fixed(self.data), **kwargs)
244 plt.ion()
245
~/anaconda3/lib/python3.6/site-packages/ipywidgets/widgets/interaction.py in __call__(self, _InteractFactory__interact_f, **kwargs)
521 # def f(*args, **kwargs):
522 # ...
--> 523 w = self.widget(f)
524 try:
525 f.widget = w
~/anaconda3/lib/python3.6/site-packages/ipywidgets/widgets/interaction.py in widget(self, f)
437 The function to which the interactive widgets are tied.
438 """
--> 439 return self.cls(f, self.opts, **self.kwargs)
440
441 def __call__(self, __interact_f=None, **kwargs):
~/anaconda3/lib/python3.6/site-packages/ipywidgets/widgets/interaction.py in __init__(self, _interactive__interact_f, _interactive__options, **kwargs)
193 getcallargs(f, **{n:v for n,v,_ in new_kwargs})
194 # Now build the widgets from the abbreviations.
--> 195 self.kwargs_widgets = self.widgets_from_abbreviations(new_kwargs)
196
197 # This has to be done as an assignment, not using self.children.append,
~/anaconda3/lib/python3.6/site-packages/ipywidgets/widgets/interaction.py in widgets_from_abbreviations(self, seq)
293 if not (isinstance(widget, ValueWidget) or isinstance(widget, fixed)):
294 if widget is None:
--> 295 raise ValueError("{!r} cannot be transformed to a widget".format(abbrev))
296 else:
297 raise TypeError("{!r} is not a ValueWidget".format(widget))
ValueError: <Figure size 360x720 with 0 Axes> cannot be transformed to a widget
<Figure size 360x720 with 0 Axes>
When passing only the axes handles, the error is
AssertionError: The axes passed are not in the figure
felixsc1 commented
I play around more with nip.plot_img() first. It seems subplots are not accepted anyways