Skip to content

Issue with appearance of RectangleSelector #17473

Closed

Description

@astrofrog

Bug report

Bug summary

The RectangleSelector example in the docs at https://matplotlib.org/3.2.1/api/widgets_api.html#matplotlib.widgets.RectangleSelector doesn't seem to produce a rectangle that renders correctly.

Code for reproduction

The example code at https://matplotlib.org/3.2.1/api/widgets_api.html#matplotlib.widgets.RectangleSelector, namely:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import RectangleSelector

def onselect(eclick, erelease):
    "eclick and erelease are matplotlib events at press and release."
    print('startposition: (%f, %f)' % (eclick.xdata, eclick.ydata))
    print('endposition  : (%f, %f)' % (erelease.xdata, erelease.ydata))
    print('used button  : ', eclick.button)

def toggle_selector(event):
    print('Key pressed.')
    if event.key in ['Q', 'q'] and toggle_selector.RS.active:
        print('RectangleSelector deactivated.')
        toggle_selector.RS.set_active(False)
    if event.key in ['A', 'a'] and not toggle_selector.RS.active:
        print('RectangleSelector activated.')
        toggle_selector.RS.set_active(True)

x = np.arange(100.) / 99
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)

toggle_selector.RS = RectangleSelector(ax, onselect, drawtype='line')
fig.canvas.mpl_connect('key_press_event', toggle_selector)
plt.show()

Actual outcome

Peek 2020-05-21 11-35

Expected outcome

I expected a rectangle to be drawn.

Matplotlib version

  • Operating system: Ubuntu 20.04
  • Matplotlib version: 3.2.1 (from pip)
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.8.2

Activity

  1. astrofrog commented on May 21, 2020

    @astrofrog
    ContributorAuthor

    Ah I think this was because the example defaults to drawtype='line' - I think this is a bit confusing as a default and 'box' might make more sense?

  2. QuLogic commented on May 21, 2020

    @QuLogic
    Member

    Why does drawtype='line' exist for something called a RectangleSelector? I think we should change that example to be less confusing.

  3. timhoffm commented on May 21, 2020

    @timhoffm
    Member

    The example was removed in favor of a link to the gallery. #17475 (comment), which uses `drawtype='box', which is also the default.

    Still, I have no clue what drawtype='line' could reasonably be used for. Maybe we should deprecate it?

  4. sjvrijn commented on Jul 23, 2021

    @sjvrijn
    Contributor

    Does the merge of #19934 mean this issue can be closed?

  5. anntzer commented on Jul 23, 2021

    @anntzer
    Contributor

    yes, thanks for pointing this out.

  6. added this to the v3.5.0 milestone on Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions