I am trying to create a legend for my 3D plot. I do not completely understand the use of a handle when it comes to making a legend.
I have followed two previously posted questions Matplotlib: Annotating a 3D scatter plot and Matplotlib scatter plot legend
What I do not understand is how to recreate their workflow when using a Dataframe.
#Creating the Graph:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# %matplotlib notebook
threedee = plt.figure(figsize = (10,10)).gca(projection='3d')
threedee.scatter(df_pca_test["PC1"],
df_pca_test["PC2"],
df_pca_test["PC3"],
c = y["y_num"] )
threedee.set_xlabel('PC1', fontsize = 12)
threedee.set_ylabel('PC2', fontsize = 12)
threedee.set_zlabel('PC3', fontsize = 12)
plt.show()
#My data:
[df_pca_test] # Contains three columns of PCA results
y[y_num] # Contains my labels in numerical format (1,2,3,4,0)
#First thing I tried:
plt.legend() # Returned: No handles with labels found to put in legend
#Second thing I tried:
plt.legend((1, 2, 3, 4, 0),
('A', 'B', 'C', 'Test', 'G'),
scatterpoints=1,
loc='lower left',
fontsize=8)
# Returned: No handles with labels found to put in legend
Ideally, I would like my graph to have a legend that has 'A', 'B', 'C', 'Test', and 'G' instead of y_num which has the numbers 1, 2, 3, 4, 0.