可以傳遞一個彩色陣列到facecolors參數,它可以設置每一個補丁在表面的顏色。
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
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)
colors = np.random.rand(40, 40, 4)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
plt.show()
'colors'在賦值之前被引用。 – diffracteD 2015-05-13 10:01:05
顏色必須導入,'輸入matplotlib.colors顏色' – lanery 2016-04-30 08:42:10
你在哪裏定義dz? dz讀起來像差動,是z方向的間隔距離嗎? – rhody 2017-10-20 20:50:53