Python: matplotlib 'numpy.ndarray' object has no attribute 'has_data'

25,955

It should be

(LTV,DTI,FICO) = readData('Acquisition_2007Q1.txt')
x = np.array(LTV)
y = np.array(DTI)
z = np.array(FICO)

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, z, cmap = cm.jet)

The Axes3D.plot_trisurf line is calling the un-bound class method plot_trisurf of the Axes3D class. It expects an instance of Axes3D to be the first argument (which is normally taken care of when the method is bound to an instance).

Share:
25,955
Eaton Chow
Author by

Eaton Chow

Updated on August 20, 2022

Comments

  • Eaton Chow
    Eaton Chow almost 2 years

    I wanted to get a 3D plot with matplotlib module. Below is some of my source code.

    (LTV,DTI,FICO) = readData('Acquisition_2007Q1.txt')
    x = np.array(LTV)
    y = np.array(DTI)
    z = np.array(FICO)
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    Axes3D.plot_trisurf(x, y, z, cmap = cm.jet)
    

    The x, y, and z are like:

    array([56, 56, 56, ..., 62, 62, 62])
    array([37, 37, 37, ..., 42, 42, 42])
    array([734, 734, 734, ..., 709, 709, 709])
    

    However, I got the error below:

    AttributeError                            Traceback (most recent call last)
    <ipython-input-22-5c9578cf3311> in <module>()
          1 fig = plt.figure()
          2 ax = fig.gca(projection='3d')
    ----> 3 Axes3D.plot_trisurf(x, y, z, cmap = cm.jet)
    
    /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpl_toolkits/mplot3d/axes3d.py in plot_trisurf(self, *args, **kwargs)
       1828         """
       1829 
    -> 1830         had_data = self.has_data()
       1831 
       1832         # TODO: Support custom face colours
    
    AttributeError: 'numpy.ndarray' object has no attribute 'has_data'
    
  • Eaton Chow
    Eaton Chow about 9 years
    True. It's very helpful! Thank you.
  • Max
    Max about 8 years
    I had the same problem because the docs for Axes3D don't give any examples.