0

I am new to python and matplotlib, I want to plot a line graph and I have 3 arrays:

np.append(self.arraynv,nv)
np.append(self.arraysvdb,Svdb)
np.append(self.arraykclen,kclen)

which I want to be x, y and z axis points respectively the code I wrote:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Axes3D.plot(self.arraynv,self.arraysvdb, self.arraykclen)
ax.show()

The error I am getting:

'numpy.ndarray' object has no attribute 'has_data'
Sanju
  • 115
  • 1
  • 13

2 Answers2

3

I believe that the issue is because you are not using the ax object that you created on this line ax = fig.add_subplot(111, projection='3d') to call the plot function on this line Axes3D.plot(self.arraynv,self.arraysvdb, self.arraykclen).

The issue is that Axes3D is a class and not an instance of itself. The plot function is part of the class Axes3D, but to be able to call it, you need to use an instance of that class which is the object that you created called ax on the previous line.

Another issue is with your last line ax.show() which the show() function cannot be called through your object ax. Use plt.show() instead.

try this:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(self.arraynv,self.arraysvdb, self.arraykclen)
plt.show()

Remember that class functions can only be called using an instance of said class then the function: x.function(arg1,arg2)

WCTech
  • 174
  • 2
  • 12
  • 2
    The code is of course correct. Concerning the explanation: `Axes3D` is the class. Its `plot` method is meant to be called on an **instance** of the class, not the class itself. `ax` is the instance of the class you want to call the `plot` method from. Maybe you can update the answer to explain that better. @Sanju if this solves the issue, consider [accepting and upvoting](https://stackoverflow.com/help/someone-answers). – ImportanceOfBeingErnest Dec 14 '17 at 11:52
0

try this:

   import matplotlib.pyplot as plt
    import numpy as np
    from sklearn.datasets import make_s_curve
    from mpl_toolkits.mplot3d import Axes3D

    '''
    make and plot 3d
    '''
    X, y = make_s_curve(n_samples=1000)
    ax = plt.axes(projection='3d')

    ax.scatter3D(X[:, 0], X[:, 1], X[:, 2], c=y)
    ax.view_init(10, -60)
    plt.show()
pd shah
  • 1,346
  • 2
  • 14
  • 26