[Tutor] Matplotlib scatterplot help

Daniel Bosah dbosah at buffalo.edu
Mon Apr 30 11:57:16 EDT 2018


I have a function in which returns scatterplot of a Isomap
<https://en.wikipedia.org/wiki/Isomap>function, which takes output from a
TF-IDF <https://en.wikipedia.org/wiki/Tf%E2%80%93idf> function, which
calculated TF-IDF values of certain articles online. I used four articles
and I want to show the 4 articles by a 3D scatterplot.

Below is the function to turn my Isomap values to a 3D scatterplot :

def Isomap(tfidf):
  jon = pd.read_csv(tfidf)
  le = preprocessing.LabelEncoder()
  tims = jon.apply(le.fit_transform)
  iso = manifold.Isomap(n_neighbors=2, n_components=3)
  john = iso.fit_transform(tims)
  fig = plt.figure()
  ax = fig.add_subplot(111, projection='3d')
  use_colors = 'rybg'
  ax.scatter(john[:,0], john[:,1],john[:,2],color=use_colors,alpha=.5) #
x,y,z coord. jon 1-3
  plt.title('Isomap of candiates')
  plt.xlabel('x')
  plt.ylabel('y')
  plt.show()
  plt.savefig('isomap.png')

The problem is that I usually only get one color returned. And even if I
get the code to print out 4 colors, I'm not sure how to get those colors
to  correspond to the four web articles.

Thanks for the help in advance.


More information about the Tutor mailing list