4

I'm trying to plot terrain elevation data with matplotlib. I build up a nx3 numpy array, with each row containing the x, y, z coordinates of my points (they're regularly spaced in a grid on the x, y plane). I am attempting to plot it with this code:

fig = plt.figure()

ax = fig.gca(projection='3d')

print desiredData[:,0]

surf = ax.plot_surface(desiredData[:,0], desiredData[:,1],
                       desiredData[:,2], rstride =1,
                       cstride = 1, cmap=cm.jet,
                       linewidth = 0, antialiased = False)

plt.show()

but I'm getting this error:

Traceback (most recent call last):
   File "gisConvert.py", line 203, in <module>
linewidth = 0, antialiased = False)
File "C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 663,
in plot_surface
rows, cols = Z.shape
ValueError: need more than 1 value to unpack

What am I doing wrong?

1 Answer 1

4

As the error suggests,

ValueError: need more than 1 value to unpack

You are using a 1D-array but plot_surface expects 2D arrays for X, Y and Z.

And that is why you get the ValueError.

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

3 Comments

Quite right. OP, check out the examples/mplot3d directory for some good examples of how to use plot_surface.
So instead of the nx3 array I should have 3 mxp arrays? I assume that's so matplotlib can identify the structure of the data?
@Ben Jones: You need 2D arrays for the co-ordinates, yes.

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.