-
Notifications
You must be signed in to change notification settings - Fork 22
Add docs on using as a third-party plugin developer #127
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guide | ||
===== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
third_party |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Third-party plugins | ||
=================== | ||
This page explains how ``napari-matplotlib`` can be used within third party plugins. | ||
|
||
``napari-matplotlib`` provides a ready-to-go widget with a Matplotlib toolbar and figure to third party plugin developers | ||
This widget is customised to match the theme of the main napari window. | ||
|
||
The widget can be found at `napari_matplotlib.base.NapariMPLWidget`. | ||
This class inherits from `QWidget <https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QWidget.html>`_. | ||
|
||
The recommended way to use `~napari_matplotlib.base.NapariMPLWidget` is inside a new widget, adding it to the layout. | ||
This means you can add additional elements to your plugin layout alongside the Matplotlib figure. | ||
Here's a short example: | ||
|
||
.. code-block:: python | ||
|
||
from qtpy.QtWidgets import QWidget | ||
from napari_matplotlib.base import NapariMPLWidget | ||
|
||
class MyPlugin(QWidget): | ||
def __init__(self, napari_viewer: napari.viewer.Viewer, parent=None): | ||
super().__init__(parent=parent) | ||
|
||
# Any custom setup for your custom widget | ||
... | ||
|
||
# Set up the plot widget | ||
plot_widget = NapariMPLWidget(napari_viewer, parent=self) | ||
self.layout().addWidget(plot_widget) | ||
|
||
The following properties and methods are useful for working with the figure and any axes within the widget: | ||
|
||
- `~.BaseNapariMPLWidget.figure` provides access to the figure | ||
- :meth:`~.BaseNapariMPLWidget.add_single_axes` adds a single axes to the figure, which can be accessed using the ``.axes`` attribute. | ||
- :meth:`~.BaseNapariMPLWidget.apply_napari_colorscheme` can be used to apply the napari colorscheme to any Axes you setup manually on the figure. | ||
|
||
Working with napari layers | ||
-------------------------- | ||
When either the layer selection or z-step in the napari viewer is changed | ||
:meth:`~.NapariMPLWidget.clear` and :meth:`~.NapariMPLWidget.draw` are called | ||
in turn. By default these do nothing, and are designed to be overriden by | ||
plugins to automatically re-draw any figures within the widget. Plugins can | ||
also override :meth:`~.NapariMPLWidget.on_update_layers` to do something when | ||
the layer selection changes. This can be used to do something without clearing | ||
or re-drawing any plots. | ||
|
||
Validating layer numbers and types | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
By default :meth:`~.NapariMPLWidget.draw` will be called when any number of any | ||
type of napari layers are selected. The `~.NapariMPLWidget.n_layers_input` | ||
and `~.NapariMPLWidget.input_layer_types` class variables can be overriden to | ||
specify the number of selected napari layers and valid layer | ||
types that are taken as input. If the number of selected layers and their | ||
types do not match up with these class variables, no re-draw is called. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.