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'
0

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

Comments

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.