You are reading an old version of the documentation (v1.5.3). For the latest version see https://matplotlib.org/stable/

Matplotlib 2.0.0rc2 is available

Install the release candidate now!

matplotlib

Travis-CI:

This Page

mplot3d example code: surface3d_demo3.pyΒΆ

(Source code, png, hires.png, pdf)

../../_images/surface3d_demo3.png
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator
import matplotlib.pyplot as plt
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, rstride=1, cstride=1, facecolors=colors,
                       linewidth=0, antialiased=False)

ax.set_zlim3d(-1, 1)
ax.w_zaxis.set_major_locator(LinearLocator(6))

plt.show()

Keywords: python, matplotlib, pylab, example, codex (see Search examples)