Skip to content

Commit cce450f

Browse files
committed
feat: add high-level zero-effort ds.piv.plot() visualization API with rich defaults
1 parent cb936cd commit cce450f

4 files changed

Lines changed: 400 additions & 47 deletions

File tree

README.md

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -70,66 +70,43 @@ Quick start (auto-detect file format):
7070

7171
## Getting Started
7272

73-
Generate an analytical multi-vortex turbulent flow field, compute vorticity, and visualize with smooth filled contours, streamlines, and velocity vectors:
73+
Load experimental PIV data or generate analytical flow fields, and visualize publication-quality flow fields with **zero effort**:
7474

7575
```python
7676
import matplotlib.pyplot as plt
77-
import numpy as np
78-
from scipy.ndimage import gaussian_filter
79-
8077
import pivpy.pivpy # registers the .piv accessor
8178
from pivpy import synthetic
8279

83-
# 1. Generate an analytical multi-vortex 2D turbulence field (or load experimental PIV data)
80+
# 1. Generate an analytical multi-vortex 2D turbulence field (or use io.read_piv)
8481
ds = synthetic.multivortex(n_frames=1, n=128, n_vortices=8, two_d=True, seed=42)
8582

86-
# 2. Compute out-of-plane vorticity: w = dv/dx - du/dy
87-
ds = ds.piv.vorticity(name="w")
88-
89-
x, y = ds["x"].values, ds["y"].values
90-
X, Y = np.meshgrid(x, y)
91-
u, v, w = ds["u"].isel(t=0).values, ds["v"].isel(t=0).values, ds["w"].isel(t=0).values
92-
93-
# Smooth vorticity for soft fluid gradient
94-
w_smooth = gaussian_filter(w, sigma=2.0)
95-
96-
# 3. Create publication-quality visualization
97-
fig, ax = plt.subplots(figsize=(8.5, 6.8), dpi=150)
98-
99-
# Smooth filled vorticity contour background
100-
vmax = np.percentile(np.abs(w_smooth), 99)
101-
cf = ax.contourf(X, Y, w_smooth, levels=100, cmap="RdBu_r", vmin=-vmax, vmax=vmax, extend="both")
102-
cbar = fig.colorbar(cf, ax=ax, pad=0.03, shrink=0.92)
103-
cbar.set_label(r"Vorticity $\omega_z = \frac{\partial v}{\partial x} - \frac{\partial u}{\partial y}\; [\mathrm{s}^{-1}]$", fontsize=11, labelpad=10)
104-
105-
# Streamlines
106-
strm = ax.streamplot(x, y, u, v, color="white", linewidth=0.75, density=1.1, arrowsize=0.8, arrowstyle="->")
107-
strm.lines.set_alpha(0.55)
108-
for patch in ax.patches:
109-
patch.set_alpha(0.55)
110-
111-
# Clean, well-proportioned velocity vector quiver overlay
112-
skip = 4
113-
q = ax.quiver(
114-
X[::skip, ::skip], Y[::skip, ::skip],
115-
u[::skip, ::skip], v[::skip, ::skip],
116-
color="#0a0a0a", angles="xy", scale_units="xy", scale=0.75,
117-
width=0.005, headwidth=4.0, headlength=5.0, headaxislength=4.5,
118-
minshaft=1.5, pivot="mid", alpha=0.9,
119-
)
120-
ax.quiverkey(q, X=0.82, Y=1.04, U=2.0, label=r"$2.0\,\mathrm{m/s}$", labelpos="E", coordinates="axes", fontproperties={"size": 10, "weight": "bold"})
121-
122-
123-
ax.set_title("PIVPy: Synthetic Multi-Vortex Field (Vorticity, Streamlines & Vectors)", fontsize=12, fontweight="bold", pad=14)
124-
ax.set_xlabel("x [mm]", fontsize=11)
125-
ax.set_ylabel("y [mm]", fontsize=11)
126-
ax.set_aspect("equal")
127-
fig.tight_layout()
83+
# 2. Zero-effort, publication-quality plot (vorticity background, streamlines & auto-scaled vectors)
84+
fig, ax = ds.piv.plot()
12885
plt.show()
12986
```
13087

13188
![PIVPy Multi-Vortex Flow Visualization](https://raw.githubusercontent.com/alexlib/pivpy/master/docs/source/_static/getting_started_quiver_vorticity.png)
13289

90+
### Customizing Your Plots
91+
92+
Every visual layer can be easily tailored or toggled:
93+
94+
```python
95+
# Velocity magnitude background with vectors only (no streamlines)
96+
fig, ax = ds.piv.plot(
97+
background="mag", # 'vorticity' (default), 'mag', 'ke', 'divergence', or None
98+
streamlines=False, # toggle flow streamlines
99+
quiver=True, # toggle velocity vectors
100+
blur=1.5, # smooth fluid color gradient
101+
arrow_scale=0.75, # custom vector arrow scale
102+
title="Velocity Magnitude & Vectors",
103+
)
104+
105+
# Clean vector quiver only (no background)
106+
fig, ax = ds.piv.plot(background=None)
107+
```
108+
109+
133110

134111

135112
Legacy loaders (still supported):

0 commit comments

Comments
 (0)