0

I created a scatter plot using a dataframe that has 3 columns (x,y,z). I am now changing the scatter plot type to an Axes3D.scatter() so that it is 3D and can rotate. Axes3D.scatter() takes two position arguments, and I don't know how to convert my 3 data points into 2.

Axes3D.scatter(xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True, *args, **kwargs)

Creates a scatter plot.

Argument--> Description xs, ys --> Positions of data points. zs--> Either an array of the same length as xs and ys or a single value to place all points in the same plane. Default is 0.

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

Axes3D.scatter(finalDf.loc[indicesToKeep, 'principal component 1']
           , finalDf.loc[indicesToKeep, 'principal component 2']
           , finalDf.loc[indicesToKeep, 'principal component 3']
           , c = colors
              )

The error I get is:

 AttributeError: 'Series' object has no attribute 'has_data'

I assume this is because the data I am giving for xs, yz is only one datapoint.

What I would like to see is a 3D scatter plot.

MrCorote
  • 565
  • 8
  • 21
hko
  • 1
  • 1
  • You cannot call the method of the class; you need to call the method of the *instance*. Similarly in 2D you would *not* try `matplotlib.axes.Axes.scatter(x,y)`, but rather, `ax = fig.add_subplot(...); ax.scatter(x,y)`. Refer to [the documentation](https://matplotlib.org/3.1.1/gallery/mplot3d/scatter3d.html) on how to produce a 3D scatter. – ImportanceOfBeingErnest Aug 25 '19 at 22:00
  • @ImportanceOfBeingErnest I don't understand what you mean by saying I need to call the method of "instance"? The code I am using is in line with the documentation. – hko Aug 27 '19 at 18:04
  • No, there is not a single example in the documentation that uses `Axes3D.scatter`. They all first create [an instance](https://www.digitalocean.com/community/tutorials/understanding-class-and-instance-variables-in-python-3) of the axes, usually called `ax`, and then call `ax.scatter`. – ImportanceOfBeingErnest Aug 27 '19 at 18:52

0 Answers0