I'm trying to generate a 3D scatter plot using Matplotlib. I would like to annotate individual points like the 2D case here: Matplotlib: How to put individual tags for a scatter plot.
I've tried to use this function and consulted the Matplotlib docoment but found it seems that the library does not support 3D annotation. Does anyone know how to do this?
Thanks!
Here's a slightly more general form of HYRY's excellent answer. It works for any list of points and labels.
There's an annoying name space problem that I could only fix by (hackily) using a global variable. If anyone can provide a better solution or explain what's going on, please let me know!
Calculate the 2D position of the point, and use it create the annotation. If you need interactive with the figure, you can recalculate the location when mouse released.
In the following posts [1], [2] the plotting of 3D arrows in matplotlib is discussed.
Similarly Annotation3D class (inherited from Annotation) can be created:
Further, we can define the annotate3D() function:
Using this function annotation tags can be added to Axes3d as in example bellow:
In case you want to make @msch's answer rotate:
Maybe easier via ax.text(...):
If you have many data points, the chart can get very cluttered if you annotate them all. The following solution (built on top of HYRY's answer) implements a mouse-over (pop-over) solution for data points in 3d charts. Only the data point next to your mouse position will be annotated. After every mouse movement, the distance of the mouse pointer to all data points is calculated, and the closest point is annotated.