From fc5bc4a50b6c16cde5e21e122fb370862b56148c Mon Sep 17 00:00:00 2001 From: Ruth Comer <10599679+rcomer@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:17:02 +0100 Subject: [PATCH] Backport PR #28739: Tweak interactivity docs wording (and fix capitalization). --- galleries/users_explain/figure/event_handling.rst | 15 +++++++++------ galleries/users_explain/figure/interactive.rst | 2 +- .../users_explain/figure/interactive_guide.rst | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/galleries/users_explain/figure/event_handling.rst b/galleries/users_explain/figure/event_handling.rst index 49d73afeb366..32da038634ae 100644 --- a/galleries/users_explain/figure/event_handling.rst +++ b/galleries/users_explain/figure/event_handling.rst @@ -251,7 +251,8 @@ is created every time a mouse is pressed:: def __call__(self, event): print('click', event) - if event.inaxes!=self.line.axes: return + if event.inaxes != self.line.axes: + return self.xs.append(event.xdata) self.ys.append(event.ydata) self.line.set_data(self.xs, self.ys) @@ -277,17 +278,19 @@ event.ydata)``. In addition to the ``LocationEvent`` attributes, it also has: Draggable rectangle exercise ---------------------------- -Write draggable rectangle class that is initialized with a +Write a draggable rectangle class that is initialized with a `.Rectangle` instance but will move its ``xy`` -location when dragged. Hint: you will need to store the original -``xy`` location of the rectangle which is stored as rect.xy and +location when dragged. + +Hint: You will need to store the original +``xy`` location of the rectangle which is stored as ``rect.xy`` and connect to the press, motion and release mouse events. When the mouse is pressed, check to see if the click occurs over your rectangle (see `.Rectangle.contains`) and if it does, store -the rectangle xy and the location of the mouse click in data coords. +the rectangle xy and the location of the mouse click in data coordinates. In the motion event callback, compute the deltax and deltay of the mouse movement, and add those deltas to the origin of the rectangle -you stored. The redraw the figure. On the button release event, just +you stored, then redraw the figure. On the button release event, just reset all the button press data you stored as None. Here is the solution:: diff --git a/galleries/users_explain/figure/interactive.rst b/galleries/users_explain/figure/interactive.rst index 6fd908fcac7a..b06283152e50 100644 --- a/galleries/users_explain/figure/interactive.rst +++ b/galleries/users_explain/figure/interactive.rst @@ -10,7 +10,7 @@ Interactive figures =================== -When working with data, interactivity can be invaluable. The pan/zoom and +Interactivity can be invaluable when exploring plots. The pan/zoom and mouse-location tools built into the Matplotlib GUI windows are often sufficient, but you can also use the event system to build customized data exploration tools. diff --git a/galleries/users_explain/figure/interactive_guide.rst b/galleries/users_explain/figure/interactive_guide.rst index 3b6f527f6d42..b08231e84f7e 100644 --- a/galleries/users_explain/figure/interactive_guide.rst +++ b/galleries/users_explain/figure/interactive_guide.rst @@ -236,7 +236,7 @@ which would poll for new data and update the figure at 1Hz. .. _spin_event_loop: -Explicitly spinning the event Loop +Explicitly spinning the event loop ---------------------------------- .. autosummary::