If you really want to highlight a point selected by the user, you can overlay another point (with dot = ax.scatter(...) ) on top of the selected point. Later, in response to user clicks, you can use dot.set_offsets((x, y)) to change the location of the point.
Joe Kington wrote a great example ( DataCursor ) on how to add an annotation that displays the coordinates of the data when the user clicks on the artist (for example, a scatter plot).
Here is an example derivative ( FollowDotCursor ) that selects and annotates data points when the user hovers the mouse over the point.
Using the DataCursor , the displayed coordinates of the data that the user clicks on are displayed โ these may not be the same coordinates as the underlying data.
With FollowDotCursor displayed data coordinate is always the point in the reference data that is closest to the mouse.
import numpy as np import matplotlib.pyplot as plt import scipy.spatial as spatial def fmt(x, y): return 'x: {x:0.2f}\ny: {y:0.2f}'.format(x=x, y=y) class FollowDotCursor(object): """Display the x,y location of the nearest data point. """ def __init__(self, ax, x, y, tolerance=5, formatter=fmt, offsets=(-20, 20)): try: x = np.asarray(x, dtype='float') except (TypeError, ValueError): x = np.asarray(mdates.date2num(x), dtype='float') y = np.asarray(y, dtype='float') self._points = np.column_stack((x, y)) self.offsets = offsets self.scale = x.ptp() self.scale = y.ptp() / self.scale if self.scale else 1 self.tree = spatial.cKDTree(self.scaled(self._points)) self.formatter = formatter self.tolerance = tolerance self.ax = ax self.fig = ax.figure self.ax.xaxis.set_label_position('top') self.dot = ax.scatter( [x.min()], [y.min()], s=130, color='green', alpha=0.7) self.annotation = self.setup_annotation() plt.connect('motion_notify_event', self) def scaled(self, points): points = np.asarray(points) return points * (self.scale, 1) def __call__(self, event): ax = self.ax
