Blocking call to interact with a figure. Wait until the user clicks *n* times on the figure, and return the coordinates of each click in a list. There are three possible interactions: - Add a point. - Remove the most recently added point. -
(self, n=1, timeout=30, show_clicks=True,
mouse_add=MouseButton.LEFT,
mouse_pop=MouseButton.RIGHT,
mouse_stop=MouseButton.MIDDLE)
| 3515 | self.canvas.print_figure(fname, **kwargs) |
| 3516 | |
| 3517 | def ginput(self, n=1, timeout=30, show_clicks=True, |
| 3518 | mouse_add=MouseButton.LEFT, |
| 3519 | mouse_pop=MouseButton.RIGHT, |
| 3520 | mouse_stop=MouseButton.MIDDLE): |
| 3521 | """ |
| 3522 | Blocking call to interact with a figure. |
| 3523 | |
| 3524 | Wait until the user clicks *n* times on the figure, and return the |
| 3525 | coordinates of each click in a list. |
| 3526 | |
| 3527 | There are three possible interactions: |
| 3528 | |
| 3529 | - Add a point. |
| 3530 | - Remove the most recently added point. |
| 3531 | - Stop the interaction and return the points added so far. |
| 3532 | |
| 3533 | The actions are assigned to mouse buttons via the arguments |
| 3534 | *mouse_add*, *mouse_pop* and *mouse_stop*. |
| 3535 | |
| 3536 | Parameters |
| 3537 | ---------- |
| 3538 | n : int, default: 1 |
| 3539 | Number of mouse clicks to accumulate. If negative, accumulate |
| 3540 | clicks until the input is terminated manually. |
| 3541 | timeout : float, default: 30 seconds |
| 3542 | Number of seconds to wait before timing out. If zero or negative |
| 3543 | will never time out. |
| 3544 | show_clicks : bool, default: True |
| 3545 | If True, show a red cross at the location of each click. |
| 3546 | mouse_add : `.MouseButton` or None, default: `.MouseButton.LEFT` |
| 3547 | Mouse button used to add points. |
| 3548 | mouse_pop : `.MouseButton` or None, default: `.MouseButton.RIGHT` |
| 3549 | Mouse button used to remove the most recently added point. |
| 3550 | mouse_stop : `.MouseButton` or None, default: `.MouseButton.MIDDLE` |
| 3551 | Mouse button used to stop input. |
| 3552 | |
| 3553 | Returns |
| 3554 | ------- |
| 3555 | list of tuples |
| 3556 | A list of the clicked (x, y) coordinates. |
| 3557 | |
| 3558 | Notes |
| 3559 | ----- |
| 3560 | The keyboard can also be used to select points in case your mouse |
| 3561 | does not have one or more of the buttons. The delete and backspace |
| 3562 | keys act like right-clicking (i.e., remove last point), the enter key |
| 3563 | terminates input and any other key (not already used by the window |
| 3564 | manager) selects a point. |
| 3565 | """ |
| 3566 | clicks = [] |
| 3567 | marks = [] |
| 3568 | |
| 3569 | def handler(event): |
| 3570 | is_button = event.name == "button_press_event" |
| 3571 | is_key = event.name == "key_press_event" |
| 3572 | # Quit (even if not in infinite mode; this is consistent with |
| 3573 | # MATLAB and sometimes quite useful, but will require the user to |
| 3574 | # test how many points were actually returned before using data). |