Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
As of 2.0,Axes3D
(frommplot3d
) inheritsannotate
from the regular 2DAxes
class. As a consequence, it takes 2D coordinates as argument (i.e., the projection done internally by mplot3d before drawing), and annotations do not follow rotation or zooming of the 3D axes.
from matplotlib import pyplot as pltfrom mpl_toolkits import mplot3dfig, ax = plt.subplots(subplot_kw={"projection": "3d"})pathcoll = ax.scatter(range(10), range(10), range(10))# ax.annotate("foo", (0, 0, 0)) raises.ax.annotate("foo", (0, 0))# Need to draw so that pathcoll.get_offsets() is updated to the 2D projection# of the coordinates.fig.canvas.draw()ax.annotate("bar", pathcoll.get_offsets()[5])plt.show()
Note that "bar" is drawn at the correct position, which happens to be close to (0, 0) in the 2D projection used by mplot3d, so "foo" ends up close to it either.
Funnily enough, it means thatmplcursors
"accidentally" works for 3D plots -- but the annotations do not follow rotation or zooming (that's how I found the issue)...