0

I want to make a 3D Graph with Matplotlib. The graph window appears, but no data is shown. What am I doing wrong?

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = [0, 10, 20, 40, 100]
y = [1, 4, 8, 60, 200]
z = [4, 5, 6, 7, 8]
ax.plot_surface(x, y, z)
plt.show()
asked Mar 13, 2013 at 17:41

2 Answers 2

1

plot_surface expects 2D inputs (doc). It is not plotting anything because you did not give it a valid surface to draw.

See this example.

answered Mar 13, 2013 at 18:13
Sign up to request clarification or add additional context in comments.

Comments

0

X, Y and Z needs to be 2D-arrays :

Surface plots Axes3D.plot_surface(X, Y, Z, *args, **kwargs) Create a surface plot.

Argument Description

X, Y, Z Data values as 2D arrays

However I do not understand the logic behind it : check this SO post for more info.

answered Mar 13, 2013 at 18:12

1 Comment

the logic is that plot_surface and the underlying functions assume that the connectivity of the points in the surface are given by the position in the matrix. This is X[i,j] has as NN X[i + 1, j], X[i, j + 1], X[i, j - 1], and X[i - 1, j]

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.