简体   繁体   中英

Plotting 3D surface from points coordinates in matplotlib

How to do something like this in matplotlib but not with points but with surface? (I have coordinates of points)

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

#X = ...
#Y = ... Some coordinates points from file it is list
#Z = ...

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

ax.scatter(X, Y, Z, c='r')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

You will have to use the plot_surface command from your ax object. I will present a code snippet from my own plotting library, you will just have to refactor it as needed. However, this (or highly similar) questions have been asked before (eg surface plots in matplotlib ).

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

def surface_plot(X,Y,Z,**kwargs):
    """ WRITE DOCUMENTATION
    """
    xlabel, ylabel, zlabel, title = kwargs.get('xlabel',""), kwargs.get('ylabel',""), kwargs.get('zlabel',""), kwargs.get('title',"")
    fig = plt.figure()
    fig.patch.set_facecolor('white')
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_surface(X,Y,Z)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    ax.set_zlabel(zlabel)
    ax.set_title(title)
    plt.show()
    plt.close()

PS: There has been a recent string of down votes on this answer. Therefore I will add that the original question was badly formulated and that this answer is exactly what the OP wanted based on a private conversation with the OP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM