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

Skip to content

Commit 2c92c4c

Browse files
committed
Merge pull request #4714 from Cadair/streamplot_seeds
Add an option to streamplot to manually specify the seed points.
2 parents b6b0e1c + ed8889f commit 2c92c4c

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Demo of the `streamplot` function.
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.
10+
"""
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
plt.ion()
14+
15+
X, Y = (np.linspace(-3, 3, 100),
16+
np.linspace(-3, 3, 100))
17+
18+
U, V = np.mgrid[-3:3:100j, 0:0:100j]
19+
20+
seed_points = np.array([[-2, 0, 1], [-2, 0, 1]])
21+
22+
fig0, ax0 = plt.subplots()
23+
strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn, start_points=seed_points.T)
24+
fig0.colorbar(strm.lines)
25+
26+
ax0.plot(seed_points[0], seed_points[1], 'bo')
27+
28+
ax0.axis((-3,3,-3,3))
29+
30+
31+
#plt.show()

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4342,7 +4342,7 @@ def stackplot(self, x, *args, **kwargs):
43424342

43434343
def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
43444344
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
4345-
minlength=0.1, transform=None, zorder=1):
4345+
minlength=0.1, transform=None, zorder=1, start_points=None):
43464346
if not self._hold:
43474347
self.cla()
43484348
stream_container = mstream.streamplot(self, x, y, u, v,
@@ -4354,6 +4354,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
43544354
arrowsize=arrowsize,
43554355
arrowstyle=arrowstyle,
43564356
minlength=minlength,
4357+
start_points=start_points,
43574358
transform=transform,
43584359
zorder=zorder)
43594360
return stream_container

lib/matplotlib/pyplot.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,10 +2662,10 @@ def broken_barh(xranges, yrange, hold=None, **kwargs):
26622662
# This function was autogenerated by boilerplate.py. Do not edit as
26632663
# changes will be lost
26642664
@_autogen_docstring(Axes.boxplot)
2665-
def boxplot(x, notch=False, sym=None, vert=True, whis=1.5, positions=None,
2666-
widths=None, patch_artist=False, bootstrap=None, usermedians=None,
2667-
conf_intervals=None, meanline=False, showmeans=False, showcaps=True,
2668-
showbox=True, showfliers=True, boxprops=None, labels=None,
2665+
def boxplot(x, notch=None, sym=None, vert=None, whis=None, positions=None,
2666+
widths=None, patch_artist=None, bootstrap=None, usermedians=None,
2667+
conf_intervals=None, meanline=None, showmeans=None, showcaps=None,
2668+
showbox=None, showfliers=None, boxprops=None, labels=None,
26692669
flierprops=None, medianprops=None, meanprops=None, capprops=None,
26702670
whiskerprops=None, manage_xticks=True, hold=None):
26712671
ax = gca()
@@ -3338,7 +3338,7 @@ def step(x, y, *args, **kwargs):
33383338
@_autogen_docstring(Axes.streamplot)
33393339
def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
33403340
norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1,
3341-
transform=None, zorder=1, hold=None):
3341+
transform=None, zorder=1, start_points=None, hold=None):
33423342
ax = gca()
33433343
# allow callers to override the hold state by passing hold=True|False
33443344
washold = ax.ishold()
@@ -3350,7 +3350,7 @@ def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
33503350
color=color, cmap=cmap, norm=norm,
33513351
arrowsize=arrowsize, arrowstyle=arrowstyle,
33523352
minlength=minlength, transform=transform,
3353-
zorder=zorder)
3353+
zorder=zorder, start_points=start_points)
33543354
finally:
33553355
ax.hold(washold)
33563356
sci(ret.lines)

lib/matplotlib/streamplot.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
2323
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
24-
minlength=0.1, transform=None, zorder=1):
24+
minlength=0.1, transform=None, zorder=1, start_points=None):
2525
"""Draws streamlines of a vector flow.
2626
2727
*x*, *y* : 1d arrays
@@ -52,6 +52,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
5252
See :class:`~matplotlib.patches.FancyArrowPatch`.
5353
*minlength* : float
5454
Minimum length of streamline in axes coordinates.
55+
*start_points*: Nx2 array
56+
Coordinates of starting points for the streamlines.
57+
In data coordinates, the same as the ``x`` and ``y`` arrays.
5558
*zorder* : int
5659
any number
5760
@@ -122,9 +125,22 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
122125
integrate = get_integrator(u, v, dmap, minlength)
123126

124127
trajectories = []
125-
for xm, ym in _gen_starting_points(mask.shape):
126-
if mask[ym, xm] == 0:
127-
xg, yg = dmap.mask2grid(xm, ym)
128+
if start_points is None:
129+
for xm, ym in _gen_starting_points(mask.shape):
130+
if mask[ym, xm] == 0:
131+
xg, yg = dmap.mask2grid(xm, ym)
132+
t = integrate(xg, yg)
133+
if t is not None:
134+
trajectories.append(t)
135+
else:
136+
# Convert start_points from data to array coords
137+
# Shift the seed points from the bottom left of the data so that
138+
# data2grid works properly.
139+
sp2 = np.asanyarray(start_points).copy()
140+
sp2[:,0] += np.abs(x[0])
141+
sp2[:,1] += np.abs(y[0])
142+
for xs, ys in sp2:
143+
xg, yg = dmap.data2grid(xs, ys)
128144
t = integrate(xg, yg)
129145
if t is not None:
130146
trajectories.append(t)

0 commit comments

Comments
 (0)