question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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')    
Screen Shot 2020-02-26 at 4 36 20 PM

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

https://github.com/matplotlib/matplotlib/blob/8ac3ea170fee9ab7b78767b9a7463332a5970880/lib/matplotlib/backends/backend_qt5.py#L502

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:open
  • Created 4 years ago
  • Reactions:5
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
dstansbycommented, May 3, 2022

👋 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 😄

2reactions
sofroniewncommented, Sep 30, 2021

Would love to work on this 😃

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found