from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
# Make data.
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
# Customize the z axis.
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
SurfacePlot
Axes3D.``plot_surface(X, Y, Z, *args, norm=None, vmin=None, vmax=None, lightsource=None, **kwargs)
这个函数算是比较常用的函数,用于绘制三维表面图,让人惊艳的是它的着色效果
Argument | Description |
X, Y,Z | 坐标点 |
rcount,ccount,rstride,cstride | 同上 |
color | 定义surface patch的颜色,type:color-like |
cmap | 定义surface patch的颜色,只不过是colorMap,type:colormap |
facecolors | 指定单个patch的颜色, type:array-like of colors |
norm | colormap的normalization, type:Normalize |
shade | 阴影效果,type:boolean |
vmin, vmax | normalization的边界 |
**kwargs | 向下传递到Poly3DCollection |
antialiased | 抗锯齿,type:boolean |