Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4e3765

Browse files
authored
Merge pull request #6672 from afvincent/fix_example_streamplot
DOC: Fix example of streamplot `start_points` option
2 parents b1d9443 + baaadcf commit d4e3765

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed
Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
"""
2-
Demo of the `streamplot` function.
2+
Demo of the streamplot function with starting points.
33
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.
106
"""
117
import numpy as np
128
import matplotlib.pyplot as plt
139

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
1813

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]])
2016

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)
2521

26-
ax0.plot(seed_points[0], seed_points[1], 'bo')
22+
ax.plot(seed_points[0], seed_points[1], 'bo')
2723

28-
ax0.axis((-3, 3, -3, 3))
24+
ax.axis((-3, 3, -3, 3))
2925

3026
plt.show()

0 commit comments

Comments
 (0)