 Modbus TCP/IP communication with PC
 How to connect Raspberry Pi 3 to the built in speaker of a pc?
 How complicated is it to light an LED?
 Could Stockfish be given enough computing power to decisively win games with only pawns?
 Reaction between 2methylbutanol and acetic acid heated with sulphuric acid?
 Is there a connection between UVdegradation and the photoelectric effect
 What is the meaning of fractional coefficients in reaction equations?
 Find all organic molecule with specific number of structual isomers
 Elements with no solid state
 Accidentally applied to my current company
 Complement of DPDA
 An optimal solution for the Pair Sum problem in a sorted array
 Find if a sequence of node is a result of a binary tree preorder traversal
 Centrality for graphs with negative weights
 How to deal with a student found seeking an answer to a coursework question online?
 Can an applicant with undergrad degree from a school that is poorly regarded be seriously considered for admission to PhD at a top business
 Ethics of staying in PhD program with no intention of being an academic, and misleading my advisor about this
 New name of a paper doesn't show up in Google
 Can alterpersonas of a person with MPD/DID have mental diseases of their own that other 'alters' don't have
 Flipping axes direction in Graphics3D
How to annotate labels in a 3D matplotlib scatter plot?
I have made a 3x3 PCA matrix with sklearn.decomposition PCA and plotted it to a matplotlib 3D scatter plot.
How can I annotate labels near the points/marker? Here is my code:
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
%matplotlib notebook
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(
existing_df_3dx['PC0'], existing_df_3dx['PC1'], existing_df_3dx['PC2'], # data
s=60 # marker size
)
plt.show()
Also, if you know of a better way to plot a 3D PCA, please post your code
Edit:
A solution provided from Stack Overflow:
for i in range(len(data_df_3dx)):
x, y, z = data_df_3dx.iloc[i]['PC1'], data_df_3dx.iloc[i]['PC2'], data_df_3dx.iloc[i]['PC3']
ax.scatter(x, y, z)
#now that you have the coordinates you can apply whatever text you need. I'm
#assuming you want the index, but you could also pass a column name if needed
ax.text(x, y, z, '{0}'.format(d

In the following posts [1], [2] the plotting of 3D arrows in matplotlib is discussed.
Similarly Annotation3D class (inherited from Annotation) can be created:
from mpl_toolkits.mplot3d.proj3d import proj_transform
from matplotlib.text import Annotation
class Annotation3D(Annotation):
'''Annotate the point xyz with text s'''
def __init__(self, s, xyz, *args, **kwargs):
Annotation.__init__(self,s, xy=(0,0), *args, **kwargs)
self._verts3d = xyz
def draw(self, renderer):
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.xy=(xs,ys)
Annotation.draw(self, renderer)
Further, we can define the annotate3D() function:
def annotate3D(ax, s, *args, **kwargs):
'''add anotation text s to to Axes3d ax'''
tag = Annotation3D(s, *args, **kwargs)
ax.add_artist(tag)
Using this function annotation tags can be added to Axes3d as in example bellow:
3D graph example
impor
20170321 00:31:16