You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NapariMPLWidget provides Matplotlib canvas and toolbar as a widget. It should be possible for external plugins to use this to avoid them having to create the canvas/toolbar themselves. How they can do this should be documented.
To pick up this discussion here - how would that work?
One approach for using the canvas within functions for napari would be something like this:
importNapariMPLWidgetdefsome_function(arg1: ImageData, arg2: float, napari_viewer: napari.viewer.Viewer=None) ->ImageData:
# function does something hereifnapari_viewerisnotNone:
widget=NapariMPLWidget()
# plot something on the widgetnapari_viewer.window.add_dock_widget(widget)
returnresult
@kevinyamauchi I think the napari_viewer argument is passed automatically if a function is exposed to the napari hook implementation...right?
Hello @jo-mueller! for the widget spec, the viewer gets passed if one of the widget __init__ kwargs is either napari_viewer or typed as napari.viewer.Viewer. When the user
I think the best pattern for now is if the plugin is a widget plugin and the NapariMPLWidget (or one of its subclasses) is added as a widget to the plugins layout. Something like this:
fromnapari_matplotlibimportScatterWidgetclassMyPlugin(QWidget):
def__init__(self, napari_viewer: napari.viewer.Viewer):
# set up some widgetsmy_widget= ...
# set up the plot widgetplot_widget=ScatterWidget(napari_viewer)
self.layout().addWidget(my_widget)
self.layout().addWidget(plot_widget)
Yes, the above comment from @kevinyamauchi is pretty much what I had in mind. Even though it's possible to use one of the "specialised" widgets, I'm imagining most people will just use NapariMPLWidget to get a blank Matplotlib figure. I'm going to try this out this afternoon with another plugin, so will report back on how it goes!
I was hoping that a plot plugin could somehow be created "on-the-fly" from a function that is exposed to magicgui. But creating a regular pyqt measurement plugin works, too.
Activity
jo-mueller commentedon May 18, 2022
To pick up this discussion here - how would that work?
One approach for using the canvas within functions for napari would be something like this:
@kevinyamauchi I think the
napari_viewer
argument is passed automatically if a function is exposed to the napari hook implementation...right?kevinyamauchi commentedon May 20, 2022
Hello @jo-mueller! for the widget spec, the viewer gets passed if one of the widget
__init__
kwargs is eithernapari_viewer
or typed asnapari.viewer.Viewer
. When the userI think the best pattern for now is if the plugin is a widget plugin and the
NapariMPLWidget
(or one of its subclasses) is added as a widget to the plugins layout. Something like this:what do you think? Is this what you had in mind?
dstansby commentedon May 23, 2022
Yes, the above comment from @kevinyamauchi is pretty much what I had in mind. Even though it's possible to use one of the "specialised" widgets, I'm imagining most people will just use
NapariMPLWidget
to get a blank Matplotlib figure. I'm going to try this out this afternoon with another plugin, so will report back on how it goes!jo-mueller commentedon Jun 2, 2022
I was hoping that a plot plugin could somehow be created "on-the-fly" from a function that is exposed to magicgui. But creating a regular pyqt measurement plugin works, too.
2 remaining items