Skip to content
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

Switch to mpl-pan-zoom #17

Merged
merged 1 commit into from
Jul 5, 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 .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