3

I know usually we use:

plot_surface(X, Y, Z)

where X, Y are 1-D array and Z a matrix of dimension len(X) × len(Y), to plot a surface.

But I now have only three columns of 1-D array as data. In other words, I have something like:

X=[1,2,3,4,5]
Y=[1,2,3,4,5]

and

Z=f(X,Y)=[1,2,3,4,5]

I do not have the expression of f, but I want to plot a surface diagram nevertheless. How should I do it?

Please feel free to ask me to clarify my question. This is my first time asking questions on the platform.

Thank you in advance!

1 Answer 1

1

is this what you mean?:

import numpy as np
import matplotlib.pyplot as plt

x=[1,2,3,4,5]
y=[1,2,3,4,5]
z=np.array([[1],[2],[3],[4],[5]])
ax = plt.axes(projection='3d')
ax.plot_surface(x, y, z,cmap='viridis')

plt.show()
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer. However when use pandas to read my csv data in an error occurs at ax.plot_surace(x, y, z, camp='viridis'). The error is "TypeError: ufunc 'isnan' not supported for the input types". Do you happen to have any idea to resolve this?
@YunhanSheng - I've found such an answer: datascience.stackexchange.com/questions/32981/… and the second one: stackoverflow.com/questions/36000993/…
Thank you ktp, this does work. Now I'm trying to read and import my own data to see if I need to adjust some details. Thanks!

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.