8000 Add new num_arrows option to streamplot by dstansby · Pull Request #27617 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add new num_arrows option to streamplot #27617

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 7 commits into from
Nov 20, 2024

Conversation

dstansby
Copy link
Member
@dstansby dstansby commented Jan 9, 2024

PR summary

This allows more than one arrow to be plotted per streamline. A rebase and tidy up of #17741.

To avoid adding a new test image I modified an existing one - I hope that's okay?

Fixes #17740

PR checklist

@dstansby dstansby mentioned this pull request Jan 9, 2024
6 tasks
@dstansby dstansby marked this pull request as ready for review January 9, 2024 15:58
@story645
Copy link
Member
story645 commented Jan 9, 2024

Yay, I have written some very hacky code to achieve this!


.. plot::
:include-source: true
:alt: One charts, identified as ax and ax2, showing a streamplot. Each streamline
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:alt: One charts, identified as ax and ax2, showing a streamplot. Each streamline
:alt: One charts, identified as ax, showing a streamplot. Each streamline

@ksunden
Copy link
Member
ksunden commented Jan 9, 2024

I might suggest using n_arrows or num_arrows or something similar, as what I would read from the signature alone is the English word "narrows" and might expect it to do something different (e.g. change linewidths at various points.)

@dstansby dstansby changed the title Add new narrows option to streamplot Add new n_arrows option to streamplot Jan 10, 2024
@github-actions github-actions bot added topic: pyplot API Documentation: examples files in galleries/examples Documentation: user guide files in galleries/users_explain or doc/users labels Jan 13, 2024
Copy link
Member
@story645 story645 left a comment

Choose a reason for hiding this comment

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

Tiny language nit.

But I also wonder if this should go on Thursdays call or get cleared by @tacaswell or @timhoffm since it's new API.


.. plot::
:include-source: true
:alt: One chart showing a streamplot. Each streamline has a three arrows.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:alt: One chart showing a streamplot. Each streamline has a three arrows.
:alt: One chart showing a streamplot. Each streamline has three arrows.

Comment on lines +77 to +79
Number of arrows per streamline. The arrows are spaced equally along the steps
each streamline takes. Note that this can be different to being spaced equally
along the distance of the streamline.
Copy link
Member

Choose a reason for hiding this comment

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

It's a little bit unclear to me why this information is important/difference between steps and distance - is there a place where this is discussed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I put this in because before I worked out why not, it was a surprise to me that the arrows weren't visually equidistant along the streamline. Happy to drop this if it causes more confusion than it clears up, or try and clarify it a bit?

Copy link
Member
@story645 story645 Jan 22, 2024

Choose a reason for hiding this comment

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

Clarify, but going by your reply I think something like this is what I'm after"

The arrows are spaced equally along the steps each streamline takes, which means they may not be spaced equally along the distance of the streamline."

Where i can just look up the diff between steps and distance

Comment on lines 230 to 232
if isinstance(linewidth, np.ndarray):
line_widths = interpgrid(linewidth, tgx, tgy)[:-1]
line_kw['linewidth'].extend(line_widths)
Copy link
Member

Choose a reason for hiding this comment

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

This can't be right? It'll extend line_kw['linewidth'] for each arrow, but it's passed to the LineCollection.

Copy link
Member

Choose a reason for hiding this comment

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

Adding num_arrows to the Varying line width plot in the example produces:
Screenshot From 2024-11-15 22-49-40
but the correct result should be:
Screenshot From 2024-11-15 22-49-51

This should be fixed now.

@timhoffm
Copy link
Member

I might suggest using n_arrows or num_arrows

I slightly favor num_arrows because that's more explicit. This is an advanced feature where saving two characters is not significant. Note: I also checked the existing Matplotlib API for similar cases, but we don't have significant comparable reference, so consistency is not an argument for one or the other.

@appopson
Copy link

Dear all,

I want to know if this option (num_arrows) is already implemented in streamplot.
How do I use it if that is not the case?

@dstansby
Copy link
Member Author

It's not currently implemented - unfortunately I don't have time at the moment to finish this PR, so someone else is welcome to pick it up and address the comments above.

@github-actions github-actions bot removed the Documentation: user guide files in galleries/users_explain or doc/users label Nov 16, 2024
@QuLogic
Copy link
Member
QuLogic commented Nov 16, 2024

I've rebased and handled the comments.

@QuLogic QuLogic added this to the v3.11.0 milestone Nov 16, 2024
@QuLogic
Copy link
Member
QuLogic commented Nov 16, 2024

Not sure why the tolerance is necessary, but it doesn't fail everywhere, so I've put it back.

@QuLogic QuLogic changed the title Add new n_arrows option to streamplot Add new num_arrows option to streamplot Nov 20, 2024
@ksunden ksunden merged commit f6a6fa6 into matplotlib:main Nov 20, 2024
43 checks passed
@dstansby
Copy link
Member Author

❤️ thanks to everyone that picked this up and pushed it over the line!

@dstansby dstansby deleted the streamplot_arrows branch November 20, 2024 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple Arrows on Streamplots
3C8D
7 participants
0