Search code examples
pythonmatplotlibsurfacematplotlib-3d

3d surface plots not showing


I am trying to make a simple 3D surface plot with matplotlib but the plot does not show at the end; I only get empty 3D axes.

Here is what I did:

from mpl_toolkits.mplot3d import Axes3D

x = np.arange(1, 100, 1)
y = np.arange(1, 100, 1)
z = np.arange(1, 100, 1)

fig = figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, rstride=5, cstride=5) 
show()

...and I get this: enter image description here

Any suggestions?


Solution

  • You are not plotting a surface: x, y and z needs to be 2D arrays. Look at this example: http://matplotlib.org/examples/mplot3d/surface3d_demo.html.