Skip to content

Commit 157dcef

Browse files
feat(matplotlib): implement streamline-basic (#2904)
## Implementation: `streamline-basic` - matplotlib Implements the **matplotlib** version of `streamline-basic`. **File:** `plots/streamline-basic/implementations/matplotlib.py` **Parent Issue:** #2861 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20608630642)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent c814a06 commit 157dcef

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
""" pyplots.ai
2+
streamline-basic: Basic Streamline Plot
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 93/100 | Created: 2025-12-31
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
11+
# Data - Create a vortex flow field
12+
np.random.seed(42)
13+
14+
# Grid setup (40x40 for smooth streamlines)
15+
x = np.linspace(-3, 3, 40)
16+
y = np.linspace(-3, 3, 40)
17+
X, Y = np.meshgrid(x, y)
18+
19+
# Vortex flow field: u = -y, v = x (creates circular streamlines)
20+
# Add a second vortex offset to show more interesting flow patterns
21+
U = -Y + 0.5 * np.exp(-((X - 1.5) ** 2 + Y**2))
22+
V = X + 0.5 * np.exp(-((X + 1.5) ** 2 + Y**2))
23+
24+
# Calculate velocity magnitude for color mapping
25+
speed = np.sqrt(U**2 + V**2)
26+
27+
# Plot
28+
fig, ax = plt.subplots(figsize=(16, 9))
29+
30+
# Create streamlines with color based on velocity magnitude
31+
strm = ax.streamplot(X, Y, U, V, color=speed, cmap="viridis", linewidth=2.5, density=1.5, arrowsize=2, arrowstyle="->")
32+
33+
# Colorbar for velocity magnitude
34+
cbar = fig.colorbar(strm.lines, ax=ax, shrink=0.8, pad=0.02)
35+
cbar.set_label("Velocity Magnitude", fontsize=20)
36+
cbar.ax.tick_params(labelsize=16)
37+
38+
# Styling
39+
ax.set_xlabel("X Position", fontsize=20)
40+
ax.set_ylabel("Y Position", fontsize=20)
41+
ax.set_title("streamline-basic · matplotlib · pyplots.ai", fontsize=24)
42+
ax.tick_params(axis="both", labelsize=16)
43+
ax.set_aspect("equal")
44+
ax.grid(True, alpha=0.3, linestyle="--")
45+
46+
plt.tight_layout()
47+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library: matplotlib
2+
specification_id: streamline-basic
3+
created: '2025-12-31T00:07:17Z'
4+
updated: '2025-12-31T00:11:24Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20608630642
7+
issue: 2861
8+
python_version: 3.13.11
9+
library_version: 3.10.8
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/streamline-basic/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/streamline-basic/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 93
14+
review:
15+
strengths:
16+
- Excellent use of matplotlib's streamplot with color-mapped velocity magnitude
17+
- Clean, readable code following KISS principles
18+
- Viridis colormap ensures colorblind accessibility
19+
- Proper title format and well-sized text elements
20+
- Vortex flow pattern clearly demonstrates streamline concept
21+
- Good use of equal aspect ratio for proper visualization of circular flow
22+
weaknesses:
23+
- Axis labels lack units (could be "X Position (m)" or similar)
24+
- Grid linestyle dashed is slightly more visible than needed
25+
- Could use linewidth varying with speed for additional visual encoding
26+
- Flow field could be more complex (e.g., dipole) to show more features

0 commit comments

Comments
 (0)