|
1 | 1 | """
|
2 |
| -Demo of the `streamplot` function. |
| 2 | +Demo of the streamplot function with starting points. |
3 | 3 |
|
4 |
| -A streamplot, or streamline plot, is used to display 2D vector fields. This |
5 |
| -example shows a few features of the stream plot function: |
6 |
| -
|
7 |
| - * Varying the color along a streamline. |
8 |
| - * Varying the density of streamlines. |
9 |
| - * Varying the line width along a stream line. |
| 4 | +This example shows how to fix the streamlines that are plotted, by passing |
| 5 | +an array of seed points to the `start_points` keyword argument. |
10 | 6 | """
|
11 | 7 | import numpy as np
|
12 | 8 | import matplotlib.pyplot as plt
|
13 | 9 |
|
14 |
| -X, Y = (np.linspace(-3, 3, 100), |
15 |
| - np.linspace(-3, 3, 100)) |
16 |
| - |
17 |
| -U, V = np.mgrid[-3:3:100j, 0:0:100j] |
| 10 | +Y, X = np.mgrid[-3:3:100j, -3:3:100j] |
| 11 | +U = -1 - X**2 + Y |
| 12 | +V = 1 + X - Y**2 |
18 | 13 |
|
19 |
| -seed_points = np.array([[-2, 0, 1], [-2, 0, 1]]) |
| 14 | +# 5 points along the first diagonal and a point in the left upper quadrant |
| 15 | +seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]]) |
20 | 16 |
|
21 |
| -fig0, ax0 = plt.subplots() |
22 |
| -strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, |
23 |
| - cmap=plt.cm.autumn, start_points=seed_points.T) |
24 |
| -fig0.colorbar(strm.lines) |
| 17 | +fig, ax = plt.subplots() |
| 18 | +strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, |
| 19 | + cmap=plt.cm.autumn, start_points=seed_points.T) |
| 20 | +fig.colorbar(strm.lines) |
25 | 21 |
|
26 |
| -ax0.plot(seed_points[0], seed_points[1], 'bo') |
| 22 | +ax.plot(seed_points[0], seed_points[1], 'bo') |
27 | 23 |
|
28 |
| -ax0.axis((-3, 3, -3, 3)) |
| 24 | +ax.axis((-3, 3, -3, 3)) |
29 | 25 |
|
30 | 26 | plt.show()
|
0 commit comments