How can I plot surface of data that I have in the form below.
Column 1 - X; Colum 2 - Y; Column 3 - Z;
In the example below there are 4 distinctive points for X and 3 for Y, however I cannot predict that, and I would have to analyze data each time to determine how to reshape columns into grid. Can I plot points just as they are? (A list of coordinates.)
[[0. 0. 0. ]
[0. 0.5 0.6989218 ]
[0. 1. 0.87790919]
[0.25 0. 0.0505097 ]
[0.25 0.5 0.7494315 ]
[0.25 1. 0.92841889]
[0.5 0. 0.09192357]
[0.5 0.5 0.79084537]
[0.5 1. 0.96983276]
[0.75 0. 0.10310818]
[0.75 0.5 0.80202997]
[0.75 1. 0.98101736]
[1. 0. 0.12209081]
[1. 0.5 0.82101261]
[1. 1. 1. ]]
If I understood your comments correctly, you are basically looking for plot_trisurf. Here data is your data matrix where I am taking first, second and third columns as x, y, z data respectively.
You don't need any reshaping for this. The input for plot_trisurf are 1-d arrays.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# data = # your matrix here
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection="3d")
x = data[:, 0]
y = data[:, 1]
z = data[:, 2]
ax.plot_trisurf(x,y,z)

In matplotlib.pyplot there is an option for scatter for 3 dims. Something like:
import matplotlib.pyplot as plt
plt.figure()
plt.scatter(x, y, z)
plt.show()
Here is documentation.
edit: For 3d plotting you can try the mpl_toolkits.mplot3d library as follows:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Axes3D.plot_surface(X, Y, Z, *args, **kwargs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With