Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit342c028

Browse files
committed
Merge pull request#849 from tonysyu/streamplot-norm-param
Add `norm` parameter to `streamplot`.
2 parents3d19a08 +7d435d4 commit342c028

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

‎lib/matplotlib/axes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6389,13 +6389,15 @@ def quiver(self, *args, **kw):
63896389
quiver.__doc__=mquiver.Quiver.quiver_doc
63906390

63916391
defstreamplot(self,x,y,u,v,density=1,linewidth=None,color=None,
6392-
cmap=None,arrowsize=1,arrowstyle='-|>',minlength=0.1):
6392+
cmap=None,norm=None,arrowsize=1,arrowstyle='-|>',
6393+
minlength=0.1):
63936394
ifnotself._hold:self.cla()
63946395
lines=mstream.streamplot(self,x,y,u,v,
63956396
density=density,
63966397
linewidth=linewidth,
63976398
color=color,
63986399
cmap=cmap,
6400+
norm=norm,
63996401
arrowsize=arrowsize,
64006402
arrowstyle=arrowstyle,
64016403
minlength=minlength)

‎lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,15 +2658,15 @@ def step(x, y, *args, **kwargs):
26582658
# This function was autogenerated by boilerplate.py. Do not edit as
26592659
# changes will be lost
26602660
@autogen_docstring(Axes.streamplot)
2661-
defstreamplot(x,y,u,v,density=1,linewidth=None,color=None,cmap=None,arrowsize=1,arrowstyle='-|>',minlength=0.10000000000000001,hold=None):
2661+
defstreamplot(x,y,u,v,density=1,linewidth=None,color=None,cmap=None,norm=None,arrowsize=1,arrowstyle='-|>',minlength=0.10000000000000001,hold=None):
26622662
ax=gca()
26632663
# allow callers to override the hold state by passing hold=True|False
26642664
washold=ax.ishold()
26652665

26662666
ifholdisnotNone:
26672667
ax.hold(hold)
26682668
try:
2669-
ret=ax.streamplot(x,y,u,v,density,linewidth,color,cmap,arrowsize,arrowstyle,minlength)
2669+
ret=ax.streamplot(x,y,u,v,density,linewidth,color,cmap,norm,arrowsize,arrowstyle,minlength)
26702670
draw_if_interactive()
26712671
finally:
26722672
ax.hold(washold)

‎lib/matplotlib/streamplot.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212

1313
defstreamplot(axes,x,y,u,v,density=1,linewidth=None,color=None,
14-
cmap=None,arrowsize=1,arrowstyle='-|>',minlength=0.1):
14+
cmap=None,norm=None,arrowsize=1,arrowstyle='-|>',
15+
minlength=0.1):
1516
"""Draws streamlines of a vector flow.
1617
1718
Parameters
@@ -31,19 +32,23 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
3132
*color* : matplotlib color code, or 2d array
3233
Streamline color. When given an array with the same shape as
3334
velocities, *color* values are converted to colors using *cmap*.
34-
*cmap* : Colormap
35+
*cmap* ::class:`~matplotlib.colors.Colormap`
3536
Colormap used to plot streamlines and arrows. Only necessary when using
3637
an array input for *color*.
38+
*norm* : :class:`~matplotlib.colors.Normalize`
39+
Normalize object used to scale luminance data to 0, 1. If None, stretch
40+
(min, max) to (0, 1). Only necessary when *color* is an array.
3741
*arrowsize* : float
3842
Factor scale arrow size.
3943
*arrowstyle* : str
40-
Arrow style specification. See `matplotlib.patches.FancyArrowPatch`.
44+
Arrow style specification.
45+
See :class:`~matplotlib.patches.FancyArrowPatch`.
4146
*minlength* : float
4247
Minimum length of streamline in axes coordinates.
4348
4449
Returns
4550
-------
46-
*streamlines* :`matplotlib.collections.LineCollection`
51+
*streamlines* ::class:`~matplotlib.collections.LineCollection`
4752
Line collection with all streamlines as a series of line segments.
4853
Currently, there is no way to differentiate between line segments
4954
on different streamlines (other than manually checking that segments
@@ -62,7 +67,8 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
6267
line_kw= {}
6368
arrow_kw=dict(arrowstyle=arrowstyle,mutation_scale=10*arrowsize)
6469

65-
ifisinstance(color,np.ndarray):
70+
use_multicolor_lines=isinstance(color,np.ndarray)
71+
ifuse_multicolor_lines:
6672
assertcolor.shape==grid.shape
6773
line_colors= []
6874
else:
@@ -95,12 +101,11 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
95101
ift!=None:
96102
trajectories.append(t)
97103

98-
# Load up the defaults - needed to get the color right.
99-
ifisinstance(color,np.ndarray):
100-
norm=matplotlib.colors.normalize(color.min(),color.max())
101-
ifcmap==None:cmap=matplotlib.cm.get_cmap(
102-
matplotlib.rcParams['image.cmap'])
103-
104+
ifuse_multicolor_lines:
105+
ifnormisNone:
106+
norm=matplotlib.colors.normalize(color.min(),color.max())
107+
ifcmapisNone:
108+
cmap=matplotlib.cm.get_cmap(matplotlib.rcParams['image.cmap'])
104109

105110
streamlines= []
106111
fortintrajectories:
@@ -113,7 +118,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
113118
points=np.transpose([tx,ty]).reshape(-1,1,2)
114119
streamlines.extend(np.hstack([points[:-1],points[1:]]))
115120

116-
## Add arrows half way along each trajectory.
121+
# Add arrows half way along each trajectory.
117122
s=np.cumsum(np.sqrt(np.diff(tx)**2+np.diff(ty)**2))
118123
n=np.searchsorted(s,s[-1]/2.)
119124
arrow_tail= (tx[n],ty[n])
@@ -124,7 +129,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
124129
line_kw['linewidth'].extend(line_widths)
125130
arrow_kw['linewidth']=line_widths[n]
126131

127-
ifisinstance(color,np.ndarray):
132+
ifuse_multicolor_lines:
128133
color_values=interpgrid(color,tgx,tgy)[:-1]
129134
line_colors.extend(color_values)
130135
arrow_kw['color']=cmap(norm(color_values[n]))
@@ -133,7 +138,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
133138
axes.add_patch(p)
134139

135140
lc=matplotlib.collections.LineCollection(streamlines,**line_kw)
136-
ifisinstance(color,np.ndarray):
141+
ifuse_multicolor_lines:
137142
lc.set_array(np.asarray(line_colors))
138143
lc.set_cmap(cmap)
139144
lc.set_norm(norm)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp