1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt from matplotlib.ticker import LinearLocator import numpy as np
fig = plt.figure() ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25) xlen = len(X) Y = np.arange(-5, 5, 0.25) ylen = len(Y) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.sin(R)
colortuple = ('y', 'b') colors = np.empty(X.shape, dtype=str) for y in range(ylen): for x in range(xlen): colors[x, y] = colortuple[(x + y) % len(colortuple)]
surf = ax.plot_surface(X, Y, Z, facecolors=colors, linewidth=0)
ax.set_zlim(-1, 1) ax.w_zaxis.set_major_locator(LinearLocator(6))
plt.show()
|