8000 Add maximum streamline length property. by gzahl · Pull Request #6062 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add maximum streamline length property. #6062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revision changes
  • Loading branch information
Manuel Jung committed Nov 21, 2016
commit c01484680925628596ddb0ce380f030f42d48781
3 changes: 2 additions & 1 deletion doc/users/whats_new/streamplot_set_maximum_length.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Maximum streamline length and integration direction can now be specified
------------------------------------------------------------------------

This allows to follow the vector field for a longer time and can enhance the visibilty of the flow pattern in some use cases.
This allows to follow the vector field for a longer time and can enhance the
visibility of the flow pattern in some use cases.
12 changes: 6 additions & 6 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
any number
*maxlength* : float
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove the "*". They are not helpful for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course i could, but all parameters in this function use the "*". It seems inconsistent if i only remove them for the new "maxlength" parameter?

Maximum length of streamline in axes coordinates.
*integration_direction* : ['foward','backward','both']
*integration_direction* : ['forward', 'backward', 'both']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify the default in the docstring?

Copy link
Member
@QuLogic QuLogic Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, according to numpydoc, it should be braces {} instead of brackets [], then the first value is the default (so put 'both' first.)

Integrate the streamline in forward, backward or both directions.

Returns:
Expand Down Expand Up @@ -101,9 +101,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
arrow_kw = dict(arrowstyle=arrowstyle, mutation_scale=10 * arrowsize)

if integration_direction not in ['both', 'forward', 'backward']:
errstr = ("Integration direction '%s' not recognised." %
integration_direction)
errstr += "Expected 'both', 'forward' or 'backward'."
errstr = ("Integration direction '%s' not recognised."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a space after the dot.

Copy link
Contributor Author
@gzahl gzahl Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, i fixed it in 7a304de
(only line 104, right?)

"Expected 'both', 'forward' or 'backward'." %
integration_direction)
raise ValueError(errstr)

if integration_direction == 'both':
Expand Down Expand Up @@ -466,8 +466,8 @@ def integrate(x0, y0):
dmap.reset_start_point(x0, y0)
s, xt, yt = _integrate_rk12(x0, y0, dmap, forward_time, maxlength)
if len(x_traj) > 0:
xt = xt[1:]
yt = yt[1:]
xt = xt[1:]
yt = yt[1:]
stotal += s
x_traj += xt
y_traj += yt
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/tests/test_streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def velocity_field():
return X, Y, U, V

def swirl_velocity_field():
x = np.linspace(-3.,3.,100)
y = np.linspace(-3.,3.,100)
X,Y = np.meshgrid(x,y)
x = np.linspace(-3., 3., 100)
y = np.linspace(-3., 3., 100)
X, Y = np.meshgrid(x, y)
a = 0.1
U = np.cos(a) * (-Y) - np.sin(a) * X
V = np.sin(a) * (-Y) + np.cos(a) * X
Expand Down Expand Up @@ -69,16 +69,16 @@ def test_masks_and_nans():
extensions=['png'])
def test_maxlength():
x, y, U, V = swirl_velocity_field()
plt.streamplot(x, y, U, V, maxlength=10., start_points=[[0.,1.5]],
linewidth=2,density=2)
plt.streamplot(x, y, U, V, maxlength=10., start_points=[[0., 1.5]],
linewidth=2, density=2)


@image_comparison(baseline_images=['streamplot_direction'],
extensions=['png'])
def test_direction():
x, y, U, V = swirl_velocity_field()
plt.streamplot(x, y, U, V, integration_direction='backward',
maxlength=1.5, start_points=[[1.5,0.]],
maxlength=1.5, start_points=[[1.5, 0.]],
linewidth=2, density=2)


Expand Down
0