Skip to content

Commit

Permalink
More improvements, mainly to docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed May 21, 2020
1 parent 6f425a1 commit 0d954b5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions regions/shapes/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,16 @@ def _update_from_mpl_selector(self, *args, **kwargs):
if self._mpl_selector_callback is not None:
self._mpl_selector_callback(self)

def as_mpl_selector(self, ax, sync=True, callback=None, **kwargs):
def as_mpl_selector(self, ax, active=True, sync=True, callback=None, **kwargs):
"""
Matplotlib editable widget for this region (`matplotlib.widgets.RectangleSelector`)
Parameters
----------
ax : `~matplotlib.axes.Axes`
The Matplotlib axes to add the selector to.
active : bool, optional
Whether the selector should be active by default.
sync : bool, optional
If `True` (the default), the region will be kept in sync with the
selector. Otherwise, the selector will be initialized with the
Expand All @@ -224,6 +226,18 @@ def as_mpl_selector(self, ax, sync=True, callback=None, **kwargs):
has been created.
kwargs
Additional keyword arguments are passed to matplotlib.widgets.RectangleSelector`
Returns
-------
selector : `matplotlib.widgets.RectangleSelector`
The Matplotlib selector.
Notes
-----
Once a selector has been created, you will need to keep a reference to
it until you no longer need it. In addition, you can enable/disable the
selector at any point by calling ``selector.set_active(True)`` or
``selector.set_active(False)``.
"""

if hasattr(self, '_mpl_selector'):
Expand All @@ -243,7 +257,7 @@ def sync_callback(*args, **kwargs):
self.center.x + self.width / 2,
self.center.y - self.height / 2,
self.center.y + self.height / 2)
self._mpl_selector.set_active(True)
self._mpl_selector.set_active(active)
self._mpl_selector_callback = callback

if sync and self._mpl_selector_callback is not None:
Expand Down

0 comments on commit 0d954b5

Please sign in to comment.