Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib: Annotating a 3D scatter plot

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!

like image 867
Yang Avatar asked Apr 29 '12 18:04

Yang


People also ask

How do I create an interactive 3D plot in matplotlib?

To generate an interactive 3D plot first import the necessary packages and create a random dataset. Now using Axes3D(figure) function from the mplot3d library we can generate a required plot directly. Pass the data to the 3D plot and configure the title and labels.

Can matplotlib be used for 3D plotting?

In order to plot 3D figures use matplotlib, we need to import the mplot3d toolkit, which adds the simple 3D plotting capabilities to matplotlib. Once we imported the mplot3d toolkit, we could create 3D axes and add data to the axes. Let's first create a 3D axes.


1 Answers

Maybe easier via ax.text(...):

from matplotlib import pyplot from mpl_toolkits.mplot3d import Axes3D from numpy.random import rand from pylab import figure    m=rand(3,3) # m is an array of (x,y,z) coordinate triplets   fig = figure() ax = fig.add_subplot(projection='3d')  for i in range(len(m)): #plot each point + it's index as text above     ax.scatter(m[i,0],m[i,1],m[i,2],color='b')      ax.text(m[i,0],m[i,1],m[i,2],  '%s' % (str(i)), size=20, zorder=1,       color='k')   ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') pyplot.show() 

enter image description here

like image 101
msch Avatar answered Oct 11 '22 05:10

msch