Skip to content

Commit

Permalink
Switch to mpl-pan-zoom
Browse files Browse the repository at this point in the history
This is the sucessor to mpl-interactions.
  • Loading branch information
JamesWrigley committed Jul 4, 2023
1 parent c8f7561 commit e7a2b81
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ipython==8.14.0
kafka-python==2.0.2
matplotlib==3.7.1
mplcursors==0.5.2
mpl-interactions==0.23.1
mpl-pan-zoom==1.0.0
numpy==1.25.0
pandas==1.5.3
pasha==0.1.1
Expand Down
22 changes: 2 additions & 20 deletions damnit/gui/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from matplotlib.figure import Figure
from matplotlib import cm as mpl_cm
from mpl_interactions import zoom_factory, panhandler
from mpl_pan_zoom import zoom_factory, PanManager, MouseButton

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -63,18 +63,6 @@ def __init__(
self._navigation_toolbar.setIconSize(QtCore.QSize(20, 20))
self._navigation_toolbar.layout().setSpacing(1)

# This is a filthy hack to stop the navigation bars box-zoom feature and
# the panhandler interfering with each other. If both of these are
# enabled at the same time then the panhandler will move the canvas
# while the user draws a box, which doesn't work very well. This way,
# the panhandler is only enabled when box zoom is disabled.
#
# Ideally the panhandler would support matplotlibs widgetLock, see:
# https://github.com/ianhi/mpl-interactions/pull/243#issuecomment-1101523740
self._navigation_toolbar._actions["zoom"].triggered.connect(
lambda checked: self.toggle_panhandler(not checked)
)

layout.addWidget(self._canvas)

if not strongly_correlated:
Expand Down Expand Up @@ -139,17 +127,11 @@ def __init__(

self._cursors = []
self._zoom_factory = None
self._panhandler = panhandler(self.figure, button=1)
self._panmanager = PanManager(self.figure, MouseButton.LEFT)

self.update_canvas(x, y, image, legend=legend)
self.figure.tight_layout()

def toggle_panhandler(self, enabled):
if enabled:
self._panhandler.enable()
else:
self._panhandler.disable()

def toggle_annotations(self, state):
if state == QtCore.Qt.Checked:
for line in self._lines.values():
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
"kafka-python",
"matplotlib",
"mplcursors",
"mpl-interactions",
"mpl-pan-zoom",
"numpy",
"pandas<2",
"PyQt5",
Expand Down

0 comments on commit e7a2b81

Please sign in to comment.