9
9
import matplotlib .collections as mcollections
10
10
import matplotlib .patches as patches
11
11
12
+
12
13
__all__ = ['streamplot' ]
13
14
14
15
@@ -46,11 +47,16 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
46
47
*minlength* : float
47
48
Minimum length of streamline in axes coordinates.
48
49
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.
54
60
"""
55
61
grid = Grid (x , y )
56
62
mask = StreamMask (density )
@@ -108,6 +114,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
108
114
cmap = cm .get_cmap (cmap )
109
115
110
116
streamlines = []
117
+ arrows = []
111
118
for t in trajectories :
112
119
tgx = np .array (t [0 ])
113
120
tgy = np .array (t [1 ])
@@ -139,6 +146,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
139
146
transform = transform ,
140
147
** arrow_kw )
141
148
axes .add_patch (p )
149
+ arrows .append (p )
142
150
143
151
lc = mcollections .LineCollection (streamlines ,
144
152
transform = transform ,
@@ -151,7 +159,17 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
151
159
152
160
axes .update_datalim (((x .min (), y .min ()), (x .max (), y .max ())))
153
161
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
155
173
156
174
157
175
# Coordinate definitions
0 commit comments