I am using matplotlib to make scatter plots. Each point on the scatter plot is associated with a named object. I would like to be able to see the name of an object when I hover my cursor over the point on the scatter plot associated with that object. In particular, it would be nice to be able to quickly see the names of the points that are outliers. The closest thing I have been able to find while searching here is the annotate command, but that appears to create a fixed label on the plot. Unfortunately, with the number of points that I have, the scatter plot would be unreadable if I labeled each point. Does anyone know of a way to create labels that only appear when the cursor hovers in the vicinity of that point?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
A slight edit on an example provided in http://matplotlib.org/users/shell.html:
This plots a straight line plot, as Sohaib was asking
mplcursors worked for me. mplcursors provides clickable annotation for matplotlib. It is heavily inspired from mpldatacursor (https://github.com/joferkington/mpldatacursor), with a much simplified API
It seems none of the other answers here actually answer the question. So here is a code that uses a scatter and shows an annotation upon hovering over the scatter points.
Because people suddenly also want to use this solution for a line
plot
instead of a scatter, the following would be the same solution forplot
(which works slightly differently).In case someone is looking for a solution for bar plots, please refer to e.g. this answer.
mpld3 solve it for me. EDIT (CODE ADDED):
You can check this example
I know it's an old question, but I kept on arriving here while looking for a solution to hover (not click on) a line.
From http://matplotlib.sourceforge.net/examples/event_handling/pick_event_demo.html :