← 返回首页
VectorsGraphic by kushalkolar · Pull Request #929 · fastplotlib/fastplotlib · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

VectorsGraphic#929

Merged
kushalkolar merged 36 commits into
mainfrom
vector-field
Nov 4, 2025
Merged

VectorsGraphic#929
kushalkolar merged 36 commits into
mainfrom
vector-field

Conversation

kushalkolar commented Oct 21, 2025
edited
Loading

Copy link
Copy Markdown
Member

closes #560

Uses instanced meshes to create the 3D vector representations and place them in 3D space.

  • VectorsGraphic graphic which is based on instanced meshes built by merging a cone and cylinder mesh.
    • VectorDirections which manages the positions of the arrows through modifying the translation elements of the transform matrix of the instance buffer
    • VectorDirections which manages the directions of the arrows through modifying the entire transform matrix of the instance buffer
    • supports static immutable single colors for now
    • auto-determines size of the arrows by estimating the density of vectors, or user can provide a specific size or specific shape for the arrows.

Can implement per-vector colors after pygfx/pygfx#1221 later in a future PR.

Can do some fun electromagnetism animations with this.

Very simple API:

figure = fpl.Figure(size=(700, 700)) start, stop, step = 0, 2 * np.pi, 0.2 # get uniform x, y positions x, y = np.meshgrid( np.arange(start, stop, step), np.arange(start, stop, step) ) # vectors, u and v indicate directions in x and y u = np.cos(x) v = np.sin(y) # positions of each vector as [n_points, 2] array positions = np.column_stack([x.ravel(), y.ravel()]) # directions of each vector as a [n_points, 2] array directions = np.column_stack([u.ravel(), v.ravel()]) vectors = figure[0, 0].add_vectors( positions=positions, directions=directions, ) figure.show()

Comment thread fastplotlib/graphics/vector_field.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/vector_field.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/features/_vectors.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/features/_vectors.py Show resolved Hide resolved

kushalkolar left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

few questions

Comment thread fastplotlib/graphics/features/_vectors.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/features/_vectors.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/features/_vectors.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/features/_vectors.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/vector_field.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/vector_field.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/vector_field.py Outdated Show resolved Hide resolved

Copy link
Copy Markdown
Member Author

Interactions work well:

vectors-2025-10-28_01.52.43.mp4
figure = fpl.Figure(size=(700, 700)) start, stop, step = 0, 2 * np.pi, 0.4 # get uniform x, y positions x, y = np.meshgrid(np.arange(start, stop, step), np.arange(start, stop, step)) # vectors, u and v are x and y components indication directions u = np.cos(x) v = np.sin(y) # positions of each vector as [n_points, 2] array positions = np.column_stack([x.ravel(), y.ravel()]) # directions of each vector as a [n_points, 2] array directions = np.column_stack([u.ravel(), v.ravel()]) vector_field = figure[0, 0].add_vector_field( positions=positions, directions=directions, ) def update(change): val = change["new"] start, stop, step = 0, 2 * np.pi, 0.4 start += val stop += val # get uniform x, y positions x, y = np.meshgrid(np.arange(start, stop, step), np.arange(start, stop, step)) # vectors, u and v are x and y components indication directions u = np.cos(x) v = np.sin(y) directions = np.column_stack([u.ravel(), v.ravel()]) vector_field.directions = directions slider = FloatSlider(value=0, min=-5, max=5, step=0.01) slider.observe(update, "value") VBox([figure.show(), slider])

Need to wait for pygfx/pylinalg#107
and pygfx/pygfx#1220

before merging into fastplotlib main

kushalkolar marked this pull request as ready for review October 30, 2025 19:42
19 hidden items Load more…

Copy link
Copy Markdown
Member Author

The recursion error with the ome-zarr file makes no sense, going to get rid of it from tests and only show the code in the docs until they fix whatever is up.

github-actions Bot commented Oct 30, 2025
edited
Loading

Copy link
Copy Markdown

📚 Docs preview built and uploaded! https://www.fastplotlib.org/ver/vector-field

kushalkolar changed the title Vector field VectorsGraphic Nov 2, 2025
Comment thread examples/image_volume/image_volume_multi_channel.py Show resolved Hide resolved
Comment thread examples/vectors/vectors_swirl.py Show resolved Hide resolved
Comment thread pyproject.toml Show resolved Hide resolved
Comment thread examples/vectors/vectors_interact_electric_charges.py Show resolved Hide resolved
Comment thread examples/vectors/vector_field_interact_charges.py Outdated Show resolved Hide resolved
Comment thread examples/vectors/vector_field_interact_charges.py Outdated Show resolved Hide resolved
Comment thread examples/vectors/vector_field_interact_charges.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/_vectors.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/_vectors.py Show resolved Hide resolved

clewis7 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Aside from that one example that won't run, everything LGTM

Hide details View details kushalkolar merged commit 61b0c01 into main Nov 4, 2025
36 checks passed
kushalkolar deleted the vector-field branch November 4, 2025 00:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

VectorsGraphic

3 participants

Footer

© 2026 GitHub, Inc.