matplotlib widgets in napari
See original GitHub issue🚀 Feature
Following some guidance from @story645 and @tacaswell we were able to get a matplotlib widget into napari using some instructions from the matplotlib documentation https://matplotlib.org/3.1.1/gallery/user_interfaces/embedding_in_qt_sgskip.html
If you have matplotlib installed then the following code will add a widget:
import numpy as np
import napari
from skimage import data
from matplotlib.backends.backend_qt5agg import FigureCanvas
from matplotlib.figure import Figure
with napari.gui_qt():
blobs_raw = data.binary_blobs(length=64, n_dim=2, volume_fraction=0.1)
viewer = napari.view_image(blobs_raw)
static_canvas = FigureCanvas(Figure(figsize=(5, 3)))
axes = static_canvas.figure.subplots()
axes.plot(blobs_raw.mean(axis=0))
viewer.window.add_dock_widget(static_canvas, area='bottom', name='matplotlib figure')

We were also discussing how to make a new figure manager so that users could just do plt.plot
and have it pop up in the dock widget. I was pointed to these two parts of matplotlib
and
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_qt5agg.py#L98
Will be great for a plugin! But putting it here for others to see too 😃 Thanks to the matplotlib team for the help!!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:11 (7 by maintainers)
Top Results From Across the Web
plugin | napari-matplotlib by David Stansby
A plugin to create Matplotlib plots from napari layers. Introduction¶. napari-matplotlib is a bridge between napari and matplotlib , making ...
Read more >Napari - widgets, storage of returned data and interactive ...
Hi, I try to code a napari widget for data image exploration. I've written an widget to execute calculations on an image layer...
Read more >napari-matplotlib - PyPI
napari -matplotlib is a bridge between napari and matplotlib , making it easy to create publication quality Matplotlib plots based on the data...
Read more >Integrating Matplotlib with napari - Chan Zuckerberg Initiative
napari is designed for high-performance qualitative data exploration, but there is often a need to map to subsequent quantitative data analysis. Matplotlib ......
Read more >Using magicgui in napari
magicgui is a python package that assists in building small, composable graphical user interfaces (widgets). It is a general abstraction layer on GUI ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
👋 I thought I’d drop by and mention that I’ve started work on a
napari-matplotlib
plugin: https://github.com/dstansby/napari-matplotlib. Currently the elevator pitch and scope are “napari-matplotlib is a bridge between napari and matplotlib, making it easy to create publication quality Matplotlib plots based on the data loaded in napari layers.”. I’d be super interested in any feedback or suggestions folks on this thread have for the plugin, including the scope I settled on for it 😄@goanpeca that’s great! As @tlambert03 said, I’d definitely encourage reaching out to and potentially teaming up with @lukasz-migas around his 1D plotting which I believe uses vispy under the hood.
Additionally I think making it as easy and smooth to do matplotlib widgets in napari makes sense - that could actually just be a really good tutorial
finally i do think it would be good if we started trying to add some additional 1D plots to napari itself, like value histograms and profiles, maybe using the 1D stuff from either a plugin or directly in napari. it’s been a while since those last convos, and i think we’ve learnt a lot as a team on how to move work forward since then