如何在matplotlib中做这样的事情,但不是用点而是用表面做? (我有点的坐标)
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()
答案 0 :(得分:1)
您必须使用plot_surface
对象中的ax
命令。我将从我自己的绘图库中提供一个代码片段,您只需根据需要进行重构。但是,之前已经问过这个(或非常相似的)问题(例如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()