|
| 1 | +''' |
| 2 | +============== |
| 3 | +3D stemplot |
| 4 | +============== |
| 5 | +
|
| 6 | +Demonstration of a basic stemplot in 3D. |
| 7 | +''' |
| 8 | + |
| 9 | +import matplotlib.pyplot as plt |
| 10 | +import numpy as np |
| 11 | + |
| 12 | +# Fixing random state for reproducibility |
| 13 | +np.random.seed(19680801) |
| 14 | + |
| 15 | + |
| 16 | +def randrange(n, vmin, vmax): |
| 17 | + ''' |
| 18 | + Helper function to make an array of random numbers having shape (n, ) |
| 19 | + with each number distributed Uniform(vmin, vmax). |
| 20 | + ''' |
| 21 | + return (vmax - vmin)*np.random.rand(n) + vmin |
| 22 | + |
| 23 | +fig = plt.figure() |
| 24 | +ax = fig.add_subplot(111, projection='3d') |
| 25 | + |
| 26 | +n = 100 |
| 27 | + |
| 28 | +# For each set of style and range settings, plot n random points in the box |
| 29 | +# defined by x in [23, 32], y in [0, 100], z in [zlow, zhigh]. |
| 30 | +for zlow, zhigh in [(-50, -25), (-30, -5)]: |
| 31 | + xs = randrange(n, 23, 32) |
| 32 | + ys = randrange(n, 0, 100) |
| 33 | + zs = randrange(n, zlow, zhigh) |
| 34 | + ax.stem(xs, ys, zs, linefmt='grey', markerfmt='D', bottom=1.1, |
| 35 | + use_line_collection=True) |
| 36 | + |
| 37 | +ax.set_xlabel('X Label') |
| 38 | +ax.set_ylabel('Y Label') |
| 39 | +ax.set_zlabel('Z Label') |
| 40 | + |
| 41 | +plt.show() |
0 commit comments