Skip to content

Remove Matplotlib pin #221

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 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ project_urls =
[options]
packages = find:
install_requires =
matplotlib<3.8
matplotlib
napari
numpy
tinycss2
Expand Down
20 changes: 9 additions & 11 deletions src/napari_matplotlib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import matplotlib
import matplotlib.style as mplstyle
import napari
from matplotlib.backends.backend_qtagg import (
FigureCanvas,
from matplotlib.backends.backend_qtagg import ( # type: ignore[attr-defined]
FigureCanvasQTAgg,
NavigationToolbar2QT,
)
from matplotlib.figure import Figure
Expand Down Expand Up @@ -49,12 +49,10 @@ def __init__(

# Sets figure.* style
with mplstyle.context(self.mpl_style_sheet_path):
self.canvas = FigureCanvas()
self.canvas = FigureCanvasQTAgg() # type: ignore[no-untyped-call]

self.canvas.figure.set_layout_engine("constrained")
self.toolbar = NapariNavigationToolbar(
self.canvas, parent=self
) # type: ignore[no-untyped-call]
self.toolbar = NapariNavigationToolbar(self.canvas, parent=self)
self._replace_toolbar_icons()
# callback to update when napari theme changed
# TODO: this isn't working completely (see issue #140)
Expand Down Expand Up @@ -97,7 +95,7 @@ def add_single_axes(self) -> None:
# Sets axes.* style.
# Does not set any text styling set by axes.* keys
with mplstyle.context(self.mpl_style_sheet_path):
self.axes = self.figure.subplots()
self.axes = self.figure.add_subplot()

def _on_napari_theme_changed(self) -> None:
"""
Expand Down Expand Up @@ -260,7 +258,7 @@ def _draw(self) -> None:
isinstance(layer, self.input_layer_types) for layer in self.layers
):
self.draw()
self.canvas.draw()
self.canvas.draw() # type: ignore[no-untyped-call]

def clear(self) -> None:
"""
Expand Down Expand Up @@ -309,8 +307,8 @@ def clear(self) -> None:
class NapariNavigationToolbar(NavigationToolbar2QT):
"""Custom Toolbar style for Napari."""

def __init__(self, *args, **kwargs): # type: ignore[no-untyped-def]
super().__init__(*args, **kwargs)
def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def]
super().__init__(*args, **kwargs) # type: ignore[no-untyped-call]
self.setIconSize(
from_napari_css_get_size_of(
"QtViewerPushButton", fallback=(28, 28)
Expand All @@ -319,7 +317,7 @@ def __init__(self, *args, **kwargs): # type: ignore[no-untyped-def]

def _update_buttons_checked(self) -> None:
"""Update toggle tool icons when selected/unselected."""
super()._update_buttons_checked()
super()._update_buttons_checked() # type: ignore[no-untyped-call]
icon_dir = self.parentWidget()._get_path_to_icon()

# changes pan/zoom icons depending on state (checked or not)
Expand Down
Binary file modified src/napari_matplotlib/tests/baseline/test_custom_theme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/baseline/test_feature_histogram2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/baseline/test_histogram_2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/baseline/test_histogram_3D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/baseline/test_slice_2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/baseline/test_slice_3D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/scatter/baseline/test_scatter_2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/napari_matplotlib/tests/scatter/baseline/test_scatter_3D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/napari_matplotlib/tests/test_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ def test_custom_stylesheet(make_napari_viewer, image_data):
assert widget.figure.patch.get_facecolor() == to_rgba("#fdf6e3")
for gridline in ax.get_xgridlines() + ax.get_ygridlines():
assert gridline.get_visible() is True
assert gridline.get_color() == "#fdf6e3"
assert gridline.get_color() == "#b0b0b0"
finally:
os.remove(style_sheet_path)