Add maximum streamline length property.#6062
Conversation
|
Can you add a test for this? Other than that seems perfectly reasonable and I agree doing the integration direction as a second PR is a good idea. Smaller changes are easier to review. |
|
I will try to set up a short test. My first interface idea for the integration direction is to change maxlength optionally in a tuple: This would give the most flexibility. Or is it too complicated? |
|
The negatives would be confusing. I think a tri-state |
|
Ok, i have added a test and copied the interface to axes and pyplot. I hope this was the right thing to do? |
|
I think just strings are good enough (just validate on the way in). You will also need to commit the test image see http://matplotlib.org/devel/testing.html#writing-an-image-comparison-test This should be a png only test I think. |
|
Hi,
Let me know, if anything has to be changed and i will try to do it tomorrow. |
|
Ok, after ironing out my rookie mistakes, i have added two more commits. edit: Seems like the last problem fixed itself! |
lib/matplotlib/axes/_axes.py
Outdated
| def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None, | ||
| cmap=None, norm=None, arrowsize=1, arrowstyle='-|>', | ||
| minlength=0.1, transform=None, zorder=2, start_points=None): | ||
| minlength=0.1, maxlength=4.0, transform=None, zorder=2, |
There was a problem hiding this comment.
All new args need to go at the end to maintain back-compatibility. The reason is if people are (un wisely!) passing in everything as positional args.
When we can drop python2 and can break API again most of these should be converted to kwarg only, but for now they need to go at the end.
|
Left a few minor comments that need to be addressed. I see what you are doing putting Could you also add an entry into https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new so that this gets properly advertised in the next release? |
|
Hi, Sorry for the delay. It seems like i don't get any Email notifications. I have hopefully addressed all the issues. |
lib/matplotlib/streamplot.py
Outdated
| *minlength* : float | ||
| Minimum length of streamline in axes coordinates. | ||
| *maxlength* : float | ||
| Maximum length of streamline in axes coordinates. |
There was a problem hiding this comment.
can you re-arrange the docstrings too?
|
The tests are failing after the merge with upstream. I have to track that down later. |
|
Sorry this got dropped! Can you rebase instead of merging upstream into your branch? See http://matplotlib.org/devdocs/devel/gitwash/development_workflow.html?highlight=rebase |
|
Thanks for the hint about a rebase rather than a merge. |
|
If you do an interactive rebase, you can delete the commits that you don't On Fri, Nov 4, 2016 at 7:04 AM, Manuel Jung notifications@github.com
|
|
Ok, thanks for the hint about the interactive rebase. The rebase is done, but the test (of course) still fail. |
|
If the diff images do not show any issue with the arrows (especially their size), then I think you are right about #6504 not being related to the test failures. |
|
Looking at the history of streamplot.py and its test file, i make the following observations:
|
|
Can you rebase and remove the extra copies of the test images? Do an interactive rebase, move the update commits right below the original addition of the files, and change the update commits to 'fixup'. |
QuLogic
left a comment
There was a problem hiding this comment.
Some minor stuff + the rebase mentioned earlier.
| 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. |
There was a problem hiding this comment.
visibilty -> visibility
Also, wrap at 80.
| # changes will be lost | ||
| @_autogen_docstring(Axes.hist) | ||
| def hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False, | ||
| def hist(x, bins=None, range=None, normed=False, weights=None, cumulative=False, |
There was a problem hiding this comment.
Yes, but this is generated by boilerplate.py. Maybe it was changed in another commit, but boilerplate.py was not run? I rerun boilerplate.py in the 9634c0e.
There was a problem hiding this comment.
I think it is because pyplot was not updated with f1b89b2 change
There was a problem hiding this comment.
That does seem right. Should this be fixed in another issue?
There was a problem hiding this comment.
It's fine to update this here. We should be better about not letting pyplot get 'stale', but it is what it is.
There was a problem hiding this comment.
Okay. I guess this request can therefore be closed.
I rebase again yesterday. Again there are unrelated changes from boilerplate.py (4775d7e
).
lib/matplotlib/streamplot.py
Outdated
| any number | ||
| *maxlength* : float | ||
| Maximum length of streamline in axes coordinates. | ||
| *integration_direction* : ['foward','backward','both'] |
There was a problem hiding this comment.
foward -> forward
- space after commas
lib/matplotlib/streamplot.py
Outdated
|
|
||
| if integration_direction not in ['both', 'forward', 'backward']: | ||
| errstr = ("Integration direction '%s' not recognised." % | ||
| integration_direction) |
lib/matplotlib/streamplot.py
Outdated
| if integration_direction not in ['both', 'forward', 'backward']: | ||
| errstr = ("Integration direction '%s' not recognised." % | ||
| integration_direction) | ||
| errstr += "Expected 'both', 'forward' or 'backward'." |
There was a problem hiding this comment.
Why not place it all in one string from the onset?
lib/matplotlib/streamplot.py
Outdated
| 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:] |
There was a problem hiding this comment.
Indent should be a multiple of 4.
| def swirl_velocity_field(): | ||
| x = np.linspace(-3.,3.,100) | ||
| y = np.linspace(-3.,3.,100) | ||
| X,Y = np.meshgrid(x,y) |
There was a problem hiding this comment.
Add space after commas in above 3 lines.
| 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) |
There was a problem hiding this comment.
Add space after commas in above two lines.
| 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.]], |
# Das ist die erste Commit-Beschreibung: Test streamplot maxlength feature. # Commit-Beschreibung matplotlib#2 wird ausgelassen: # Added streamline maxlength test png baseline image.
|
@QuLogic Github still shows me a requested change, but i think i did all revisions? Otherwise please leave me a hint what is missing. Thanks! |
| In data coordinates, the same as the ``x`` and ``y`` arrays. | ||
| *zorder* : int | ||
| any number | ||
| *maxlength* : float |
There was a problem hiding this comment.
Can you please remove the "*". They are not helpful for readability.
There was a problem hiding this comment.
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?
| any number | ||
| *maxlength* : float | ||
| Maximum length of streamline in axes coordinates. | ||
| *integration_direction* : ['forward', 'backward', 'both'] |
There was a problem hiding this comment.
Can you specify the default in the docstring?
There was a problem hiding this comment.
Oh, according to numpydoc, it should be braces {} instead of brackets [], then the first value is the default (so put 'both' first.)
| #======================== | ||
|
|
||
| def get_integrator(u, v, dmap, minlength): | ||
| def get_integrator(u, v, dmap, minlength, maxlength, integration_direction): |
There was a problem hiding this comment.
I don't think this needs to be public. Can you make this function private?
There was a problem hiding this comment.
Ok, if it was public, i should leave it like that?
|
Hi @gzahl |
|
Unfortunately, that function is not new (WRT this PR, at least.) |
|
Indeed, it is not… (I am clearly not caffeinated enough). |
|
Glad this finally got merged! @gzahl Thanks for your contribution and sorry the review took so long! |
|
Thanks @tacaswell and all the others for your patience! |
Hello,
I have added the option to specify the maximum streamline length. This is handy if one e.g. only needs a single (or a few) streamlines. It is especially handy if used together with "start_points".
This may be enhanced by forcing only forward (or backward) streamline integration. But that should probably be taken care of in another patch. Do you agree?