0

I'been trying to plot a 3D-image with an array as input. For testing I made an little np.array

ar = np.array([[1,2,3],[4,5,6],[7,8,9]])

My idea was to use the x-positions as x-value, the y-positions as y-value and the value of each position as z-value.

fig = plt.figure(figsize=(12,10))
ax = fig.add_subplot(111, projection='3d')

plt.title("Titel")
X = range(len(a))
Y = range(len(a))
Z = a
ax.plot_surface(X,Y,Z, cmap=plt.cm.Reds, cstride=1, rstride=1)

My problem is that I get an plot, but the plot isnt like I tought it gonna be... Plot

I want a "normal" surface plot, like this: normal plot

In the Docs is explained how to make 3D plot with functions as input, but I didnt find a good description how to do it with an array.

Sry for the big pictures, I dont know how to make them smaller :/

1 Answer 1

0

Found the solution in this question:Plotting a 2D Array with Matplotlib

Dont know why I didnt see it before.

Adding

x = range(len(a))
y = range(len(a))
X,Y = np.meshgrid(x,y)
Z = a

gives this plot: plot

I dont know what exactly does "meshgrid"... gonna search a little bit more about it.

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.