Skip to content

Conversation

cvanelteren
Copy link
Collaborator

@cvanelteren cvanelteren commented Oct 6, 2025

This PR introduces a new plotting feature: curved_quiver, a method for drawing curved vector field arrows (streamlines with arrows) for 2D vector fields. This method provides a visually intuitive way to represent vector fields, combining the clarity of streamlines with the directionality of arrows.

comparison

Motivation

  • Enhanced Visualization: Traditional quiver plots use straight arrows, which can be misleading for complex flows. curved_quiver uses streamlines with arrows, making vector field direction and magnitude easier to interpret.
  • User Request: This feature was suggested by user @Yefee, who advocated for a more declarative and modular approach to vector field visualization.
  • Consistency: The implementation aligns with the project’s style, using clear, single-responsibility helper functions for maintainability and extensibility.

Attribution

  • The core logic of curved_quiver is adapted from the Deltares dfm_tools repository.

Features

  • Draws curved arrows along streamlines for 2D vector fields.
  • Supports customization of color, linewidth, colormap, arrow size/style, density, and more.
  • Accepts user-defined starting points for streamlines.
  • Returns a container object (CurvedQuiverSet) with both the line and arrow collections for further manipulation or legend creation.
  • Modular implementation: major steps are handled by private, well-documented helper functions.

Usage Example

fig, ax = uplt.subplots()
x = np.linspace(-4, 4, 20)
y = np.linspace(-3, 3, 20)
X, Y = np.meshgrid(x, y)
U = -Y
V = X
speed = np.sqrt(U**2 + V**2)
cq = ax.curved_quiver(X, Y, U, V, color=speed, arrow_at_end=True, scale=2.0, grains=10)
fig.colorbar(cq.lines, ax=ax, label="speed")

Acknowledgement

This feature was suggested by user @Yefee, who requested a declarative, helper-driven approach for curved vector field arrows.

Impact

  • Adds a new, powerful visualization tool for vector fields.
  • No breaking changes; fully additive.
  • Comprehensive tests included for all helper functions and main plotting logic.

@cvanelteren cvanelteren changed the title Feat curved quiever Add curved_quiver — Curved Vector Field Arrows for 2D Plots Oct 6, 2025
@cvanelteren cvanelteren requested a review from Copilot October 6, 2025 15:09
Copilot

This comment was marked as resolved.

cvanelteren and others added 5 commits October 6, 2025 17:11
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cvanelteren cvanelteren marked this pull request as draft October 6, 2025 15:17
Copy link

codecov bot commented Oct 6, 2025

Codecov Report

❌ Patch coverage is 80.84112% with 82 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/axes/plot_types/curved_quiver.py 78.53% 38 Missing and 9 partials ⚠️
ultraplot/axes/plot.py 72.65% 17 Missing and 18 partials ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren
Copy link
Collaborator Author

cvanelteren commented Oct 6, 2025

  • Proof of principle is implemented. Need to refactor now before asking for review.

@cvanelteren cvanelteren self-assigned this Oct 6, 2025
@cvanelteren
Copy link
Collaborator Author

cvanelteren commented Oct 7, 2025

Pinging @veenstrajelmer. I wrote a wrapper around the code that was introduced in dfm_tools but we have a licensing issue. That repository uses GPL3.0 and we use MIT. I am not too sure if under the current wrapper it satisfies GPL3.0. Could you chip in on this?

@cvanelteren cvanelteren requested a review from Copilot October 7, 2025 16:33
Copilot

This comment was marked as resolved.

cvanelteren and others added 4 commits October 7, 2025 18:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
cvanelteren and others added 2 commits October 7, 2025 19:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@veenstrajelmer
Copy link

veenstrajelmer commented Oct 7, 2025

I wrote a wrapper around the code that was introduced in dfm_tools but we have a licensing issue. That repository uses GPL3.0 and we use MIT. I am not too sure if under the current wrapper it satisfies GPL3.0. Could you chip in on this?

That should be no issue I think, feel free to take it and adapt it as you wish. As written in the docstring of modplot.py, the code in that file is an improved version of https://github.com/kieranmrhunt/curved-quivers/blob/master/modplot.py (which has no licence), this again was based largely on matplotlibs streamplot functionality. I made the code in dfm_tools such that the diff was minimal with the matplotlib.streamplot code (at the time). I also hoped matplotlib would adopt it for that reason, as you probably read in the discussion in matplotlib/matplotlib#20038. So please ignore the dfm_tools license for this script, and feel free to use and adopt it as you please.

@cvanelteren cvanelteren marked this pull request as ready for review October 7, 2025 18:13
@cvanelteren cvanelteren requested a review from beckermr October 7, 2025 18:13
Copy link
Collaborator

@beckermr beckermr left a comment

Choose a reason for hiding this comment

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

A bit more stuff on the class names. Looking good!

cvanelteren and others added 7 commits October 13, 2025 18:05
Co-authored-by: Matthew R. Becker <beckermr@users.noreply.github.com>
Co-authored-by: Matthew R. Becker <beckermr@users.noreply.github.com>
Co-authored-by: Matthew R. Becker <beckermr@users.noreply.github.com>
Co-authored-by: Matthew R. Becker <beckermr@users.noreply.github.com>
@cvanelteren
Copy link
Collaborator Author

@beckermr done merge away when ready.

@beckermr beckermr enabled auto-merge (squash) October 13, 2025 16:31
@beckermr beckermr merged commit 8ff97b0 into Ultraplot:main Oct 13, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants