Skip to content

Update the documentation of Cursor #12959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,28 +1257,34 @@ def funchspace(self, val):

class Cursor(AxesWidget):
"""
A horizontal and vertical line that spans the axes and moves with
the pointer. You can turn off the hline or vline respectively with
the following attributes:
A crosshair cursor that spans the axes and moves with mouse cursor.

*horizOn*
Controls the visibility of the horizontal line
For the cursor to remain responsive you must keep a reference to it.

*vertOn*
Controls the visibility of the horizontal line

and the visibility of the cursor itself with the *visible* attribute.
Parameters
----------
ax : `matplotlib.axes.Axes`
The `~.axes.Axes` to attach the cursor to.
horizOn : bool, optional, default: True
Whether to draw the horizontal line.
vertOn : bool, optional, default: True
Whether to draw the vertical line.
useblit : bool, optional, default: False
Use blitting for faster drawing if supported by the backend.

Other Parameters
----------------
**lineprops
`.Line2D` porperties that control the appearance of the lines.
See also `~.Axes.axhline`.

For the cursor to remain responsive you must keep a reference to
it.
Examples
--------
See :doc:`/gallery/widgets/cursor`.
"""

def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
**lineprops):
"""
Add a cursor to *ax*. If ``useblit=True``, use the backend-dependent
blitting features for faster updates. *lineprops* is a dictionary of
line properties.
"""
AxesWidget.__init__(self, ax)

self.connect_event('motion_notify_event', self.onmove)
Expand All @@ -1298,7 +1304,7 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
self.needclear = False

def clear(self, event):
"""clear the cursor"""
"""Internal event handler to clear the cursor."""
if self.ignore(event):
return
if self.useblit:
Expand All @@ -1307,7 +1313,7 @@ def clear(self, event):
self.lineh.set_visible(False)

def onmove(self, event):
"""on mouse motion draw the cursor if visible"""
"""Internal event handler to draw the cursor when the mouse moves."""
if self.ignore(event):
return
if not self.canvas.widgetlock.available(self):
Expand All @@ -1332,17 +1338,14 @@ def onmove(self, event):
self._update()

def _update(self):

if self.useblit:
if self.background is not None:
self.canvas.restore_region(self.background)
self.ax.draw_artist(self.linev)
self.ax.draw_artist(self.lineh)
self.canvas.blit(self.ax.bbox)
else:

self.canvas.draw_idle()

return False


Expand Down