-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Labels
Milestone
Description
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
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