Mark this answer . Basically, you set up a selection event that creates an annotation on the chart. This annotation may appear as a text field in a tooltip style.
Please note that this does not create a real βwindowβ for the graphical interface (ie a dialog box or other control with a close button, title, etc.), but simply annotations on the plot itself. However, looking at the code, you can see how it identifies the artist (for example, the point) that you clicked on. Once you have this information, you can run any code you need, for example, by creating a wxPython dialog instead of an annotation.
Edit the question about the last few lines: based on your code, it looks like you want:
pts = self.map.scatter(x, y, 90) self.figure.canvas.mpl_connect('pick_event', DataCursor(plt.gca())) pts.set_picker(5)
Another editing option is the question of whether there is another text in the annotation. You may need to play a little with the event object to extract the information you need. As described in http://matplotlib.sourceforge.net/users/event_handling.html#simple-picking-example , different types of artists (i.e. different kinds of charts) will provide information about different events.
I have an old code that does almost what you described (displaying the name of the city when you click a point on the map). I have to admit that I donβt remember exactly how it all works, but my code has this in a DataCursor:
def __call__(self, event): self.event = event xdata, ydata = event.artist._offsets[:,0], event.artist._offsets[:,1] #self.x, self.y = xdata[event.ind], ydata[event.ind] self.x, self.y = event.mouseevent.xdata, event.mouseevent.ydata if self.x is not None: city = clim['Name'][event.ind[0]] if city == self.annotation.get_text() and self.annotation.get_visible(): # You can click the visible annotation to remove it self.annotation.set_visible(False) event.canvas.draw() return self.annotation.xy = self.x, self.y self.annotation.set_text(city) self.annotation.set_visible(True) event.canvas.draw()
clim['Name'] is a list of city names, and I was able to index it using event.ind to get the city name corresponding to the selected point. Your code may be slightly different depending on the format of your data, but this should give you an idea.