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

Skip to content

Commit 7a61238

Browse files
committed
Merge pull request #803 from tonysyu/streamplot-return-arrows
Return arrow collection as 2nd argument of streamplot.
2 parents 4c1d072 + a7248d9 commit 7a61238

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

lib/matplotlib/axes.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6601,17 +6601,17 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
66016601
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
66026602
minlength=0.1, transform=None):
66036603
if not self._hold: self.cla()
6604-
lines = mstream.streamplot(self, x, y, u, v,
6605-
density=density,
6606-
linewidth=linewidth,
6607-
color=color,
6608-
cmap=cmap,
6609-
norm=norm,
6610-
arrowsize=arrowsize,
6611-
arrowstyle=arrowstyle,
6612-
minlength=minlength,
6613-
transform=transform)
6614-
return lines
6604+
stream_container = mstream.streamplot(self, x, y, u, v,
6605+
density=density,
6606+
linewidth=linewidth,
6607+
color=color,
6608+
cmap=cmap,
6609+
norm=norm,
6610+
arrowsize=arrowsize,
6611+
arrowstyle=arrowstyle,
6612+
minlength=minlength,
6613+
transform=transform)
6614+
return stream_container
66156615
streamplot.__doc__ = mstream.streamplot.__doc__
66166616

66176617
@docstring.dedent_interpd

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
30553055
draw_if_interactive()
30563056
finally:
30573057
ax.hold(washold)
3058-
sci(ret)
3058+
sci(ret.lines)
30593059
return ret
30603060

30613061
# This function was autogenerated by boilerplate.py. Do not edit as

lib/matplotlib/streamplot.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import matplotlib.collections as mcollections
1010
import matplotlib.patches as patches
1111

12+
1213
__all__ = ['streamplot']
1314

1415

@@ -46,11 +47,16 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
4647
*minlength* : float
4748
Minimum length of streamline in axes coordinates.
4849
49-
Returns *streamlines* : :class:`~matplotlib.collections.LineCollection`
50-
Line collection with all streamlines as a series of line segments.
51-
Currently, there is no way to differentiate between line segments
52-
on different streamlines (other than manually checking that segments
53-
are connected).
50+
Returns
51+
-------
52+
*stream_container* : StreamplotSet
53+
Container object with attributes
54+
lines : `matplotlib.collections.LineCollection` of streamlines
55+
arrows : collection of `matplotlib.patches.FancyArrowPatch` objects
56+
repesenting arrows half-way along stream lines.
57+
This container will probably change in the future to allow changes to
58+
the colormap, alpha, etc. for both lines and arrows, but these changes
59+
should be backward compatible.
5460
"""
5561
grid = Grid(x, y)
5662
mask = StreamMask(density)
@@ -108,6 +114,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
108114
cmap = cm.get_cmap(cmap)
109115

110116
streamlines = []
117+
arrows = []
111118
for t in trajectories:
112119
tgx = np.array(t[0])
113120
tgy = np.array(t[1])
@@ -139,6 +146,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
139146
transform=transform,
140147
**arrow_kw)
141148
axes.add_patch(p)
149+
arrows.append(p)
142150

143151
lc = mcollections.LineCollection(streamlines,
144152
transform=transform,
@@ -151,7 +159,17 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
151159

152160
axes.update_datalim(((x.min(), y.min()), (x.max(), y.max())))
153161
axes.autoscale_view(tight=True)
154-
return lc
162+
163+
ac = matplotlib.collections.PatchCollection(arrows)
164+
stream_container = StreamplotSet(lc, ac)
165+
return stream_container
166+
167+
168+
class StreamplotSet(object):
169+
170+
def __init__(self, lines, arrows, **kwargs):
171+
self.lines = lines
172+
self.arrows = arrows
155173

156174

157175
# Coordinate definitions

0 commit comments

Comments
 (0)