0

I have the following data, trying to plot a 3d surface.

data = [[10, 10, 0.84496124031007758],
    [10, 20, 0.87209302325581395],
    [10, 30, 0.88139534883720927],
    [20, 10, 0.86201550387596892],
    [20, 20, 0.87441860465116272],
    [20, 30, 0.88992248062015500],
    [30, 10, 0.87984496124031009],
    [30, 20, 0.89922480620155043],
    [30, 30, 0.92015503875968996]]

x, y, z = zip(*data)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(x, y, z,cmap='viridis', edgecolor='none')
plt.show()

I am retrieving below error,

File "C:/Users/40227422/PycharmProjects/VideoDetection.py", line 29, in <module>
   ax.plot_surface(x, y, z,cmap='viridis', edgecolor='none')
File "C:\Users\40227422\AppData\Local\Continuum\miniconda3\envs\tensorflow\lib\site- 
packages\mpl_toolkits\mplot3d\axes3d.py", line 1496, in plot_surface
   if Z.ndim != 2:
AttributeError: 'tuple' object has no attribute 'ndim'

Thanks in advance

1 Answer 1

1

The first three arguments of Axes3D.plot_surface all need to be 2D arrays.

Replacing your call with the following will work:

ax.plot_surface(np.array(x).reshape(3,3), np.array(y).reshape(3,3), np.array(z).reshape(3,3), cmap='viridis', edgecolor='none')

Or with a list comprehension + destructuring:

ax.plot_surface(*[np.array(d).reshape(3,3) for d in zip(*data)], cmap='viridis', edgecolor='none')
Sign up to request clarification or add additional context in comments.

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.