I'm plotting a time series using pyplot
and want to highlight a point once it is selected (using a pick_event
). Found a similar problem here, but just can't get my head around it. This is a basic example of what I do:
import matplotlib.pyplot as plt
class MyPlot(object):
def __init__(self, parent=None):
super(self.__class__, self).__init__()
def makePlot(self):
fig = plt.figure('Test', figsize=(10, 8))
ax = plt.subplot(111)
x = range(0, 100, 10)
y = (5,)*10
ax.plot(x, y, '-', color='red')
ax.plot(x, y, 'o', color='blue', picker=5)
plt.connect('pick_event', self.onPick)
plt.show()
def onPick(self, event=None):
this_point = event.artist
x_value = this_point.get_xdata()
y_value = this_point.get_ydata()
ind = event.ind
print 'x:{0}'.format(x_value[ind][0])
print 'y:{0}'.format(y_value[ind][0])
if __name__ == '__main__':
app = MyPlot()
app.makePlot()
The selected point shall be marked (e.g. by making it yellow), but when I pick another point, it shall be resetted back to blue and only the newly picked point shall be highlighted (no annotations, just the color change). How can I do this?