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!
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.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With