title: 3D plotting in Python - Adding a Legend to Scatterplot
body: <pre><code>from mpl_toolkits.mplot3d import Axes3D
  
  ax.scatter(X_lda[:,0], X_lda[:,1], X_lda[:,2], alpha=0.4, c=y_train, cmap='rainbow', s=20)
  
  plt.legend()
  plt.show()
  
  </code></pre>
  
  <p>Essentially I'd like to add a legend for the scatterplot that shows the unique values in y_train and what color point it corresponds to on the plot.</p>
  
  <p>The output plot:
  <a href="https://i.stack.imgur.com/RMZQ7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RMZQ7.png" alt="Plot"></a></p>