Closed
Description
... and it should not.
The visualization of plots in matplotlib change after napari_matplotlib
has been imported. Global settings e.g. here should not be modified by a napari-plugin. Consider programming napari-plugins side-effect free.
To reproduce:
import matplotlib.pyplot as plt
import numpy as np
image = np.random.random((3,3))
plt.imshow(image)
import napari_matplotlib
plt.imshow(image)
The same can be observed when not importing napari_matplotlib
but instead opening a viewer where napari-stress is installed, because starting the viewer imports napari_stress
and this imports napari_matplotlib
in the background. A napari-plugin should not modify how things are displayed in jupyter notebooks. It's kind of evil usage of global variables.
CC @jo-mueller
Activity
haesleinhuepf commentedon Jan 28, 2023
We had a similar issue earlier in another plugin and this is how we solved it:
https://github.com/BiAPoL/napari-clusters-plotter/blob/b917c1c7e01acf28b24fdbe64913e20588bed642/napari_clusters_plotter/_Qt_code.py#L257-L274
I hope this helps! :-)
jo-mueller commentedon Jan 30, 2023
Hi @haesleinhuepf ,
I think a similar issue has been discussed here and I thought it was also seeb as not desirable to change the global matplotlib behavior. I've seen the same thing happening for other plots (napari-style color scheme) so the global variables must have been set somewhere else, anyway.
Another quick fix that I use a lot would be:
haesleinhuepf commentedon Jan 30, 2023
That's a great workaround. Thanks, @jo-mueller .
Can you give an example and create a GitHub issue on the affected project?
jo-mueller commentedon Jan 30, 2023
@haesleinhuepf
I mean more that the matplotlib global variables must have been set somewhere else within the scope of napari-matplotlib. I think here. A workaround would be to set the ax parameters (facecolors, etc) where the
canvas.axes
objects are created, e.g. here and here.@dstansby would it be acceptable for you to define the display parameters in the
__init__
of the respective "end-user" widget definitions? Doing so would probably also close #36.Test to guard against re-introducing matplotlib#64.
Test to guard against re-introducing matplotlib#64.
Test to guard against re-introducing matplotlib#64.
Test to guard against re-introducing matplotlib#64.