Skip to content

Commit 483abdc

Browse files
feat(plotly): implement polar-bar (#2743)
## Implementation: `polar-bar` - plotly Implements the **plotly** version of `polar-bar`. **File:** `plots/polar-bar/implementations/plotly.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20601055131)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent ec8dca3 commit 483abdc

2 files changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
""" pyplots.ai
2+
polar-bar: Polar Bar Chart (Wind Rose)
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import plotly.graph_objects as go
9+
10+
11+
# Data: Wind speed distribution by direction (8 compass points)
12+
# Each direction has 3 speed ranges (stacked bars)
13+
np.random.seed(42)
14+
15+
directions = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
16+
17+
# Wind speed frequencies by direction (simulating typical coastal wind patterns)
18+
# Light breeze (0-10 km/h)
19+
light = np.array([8, 5, 4, 3, 6, 12, 15, 10])
20+
# Moderate breeze (10-20 km/h)
21+
moderate = np.array([6, 4, 3, 2, 4, 10, 12, 8])
22+
# Strong breeze (20+ km/h)
23+
strong = np.array([3, 2, 1, 1, 2, 5, 6, 4])
24+
25+
# Create figure with polar subplot
26+
fig = go.Figure()
27+
28+
# Add stacked bars for each wind speed category (base is cumulative)
29+
fig.add_trace(
30+
go.Barpolar(
31+
r=light,
32+
theta=directions,
33+
name="Light (0-10 km/h)",
34+
marker=dict(color="#306998", line=dict(color="white", width=2)),
35+
opacity=0.9,
36+
)
37+
)
38+
39+
fig.add_trace(
40+
go.Barpolar(
41+
r=moderate,
42+
theta=directions,
43+
name="Moderate (10-20 km/h)",
44+
marker=dict(color="#FFD43B", line=dict(color="white", width=2)),
45+
opacity=0.9,
46+
)
47+
)
48+
49+
fig.add_trace(
50+
go.Barpolar(
51+
r=strong,
52+
theta=directions,
53+
name="Strong (20+ km/h)",
54+
marker=dict(color="#4ECDC4", line=dict(color="white", width=2)),
55+
opacity=0.9,
56+
)
57+
)
58+
59+
# Update layout for polar chart
60+
fig.update_layout(
61+
title=dict(text="polar-bar · plotly · pyplots.ai", font=dict(size=32, color="#333"), x=0.5, y=0.95),
62+
polar=dict(
63+
barmode="stack",
64+
radialaxis=dict(
65+
visible=True,
66+
range=[0, max(light + moderate + strong) + 3],
67+
tickfont=dict(size=18),
68+
tickangle=45,
69+
gridcolor="rgba(0,0,0,0.2)",
70+
linecolor="rgba(0,0,0,0.3)",
71+
title=dict(text="Frequency (%)", font=dict(size=18)),
72+
),
73+
angularaxis=dict(
74+
tickfont=dict(size=22, color="#333"),
75+
direction="clockwise",
76+
rotation=90, # N at top
77+
gridcolor="rgba(0,0,0,0.15)",
78+
linecolor="rgba(0,0,0,0.3)",
79+
),
80+
bgcolor="rgba(255,255,255,0.95)",
81+
),
82+
legend=dict(
83+
font=dict(size=20),
84+
x=0.85,
85+
y=0.95,
86+
bgcolor="rgba(255,255,255,0.9)",
87+
bordercolor="rgba(0,0,0,0.2)",
88+
borderwidth=1,
89+
),
90+
template="plotly_white",
91+
margin=dict(l=80, r=180, t=120, b=80),
92+
)
93+
94+
# Save as PNG (4800 x 2700 px)
95+
fig.write_image("plot.png", width=1600, height=900, scale=3)
96+
97+
# Save interactive HTML
98+
fig.write_html("plot.html", include_plotlyjs=True, full_html=True)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
library: plotly
2+
specification_id: polar-bar
3+
created: '2025-12-30T16:29:47Z'
4+
updated: '2025-12-30T16:35:48Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20601055131
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 6.5.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/polar-bar/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/polar-bar/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/polar-bar/plotly/plot.html
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent wind rose visualization with properly stacked bars for three wind speed
17+
categories
18+
- Clean polar layout with N correctly positioned at top using rotation=90 and clockwise
19+
direction
20+
- Good color scheme with white bar separators enhancing readability
21+
- Proper use of Plotly Barpolar trace for polar bar charts
22+
- Realistic coastal wind pattern data with believable directional distribution
23+
weaknesses:
24+
- Radial axis tick labels are slightly small and angled, could be larger for better
25+
legibility
26+
- Does not leverage Plotly interactive features like custom hover templates
27+
- Legend text could benefit from slightly better styling to match overall polish

0 commit comments

Comments
 (0)