Skip to content

Commit 46029d9

Browse files
feat(plotly): implement polar-line (#2754)
## Implementation: `polar-line` - plotly Implements the **plotly** version of `polar-line`. **File:** `plots/polar-line/implementations/plotly.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20601054802)* --------- 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 fbcb4a2 commit 46029d9

2 files changed

Lines changed: 124 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
""" pyplots.ai
2+
polar-line: Polar Line Plot
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 94/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import plotly.graph_objects as go
9+
10+
11+
# Data - Average hourly temperature pattern (two seasons)
12+
np.random.seed(42)
13+
hours = np.arange(0, 360, 15) # 24 hours mapped to 360 degrees (15 deg = 1 hour)
14+
hour_labels = [f"{h}:00" for h in range(24)]
15+
16+
# Summer pattern: warmer during day (12-18h), cooler at night
17+
summer_base = 22 + 8 * np.sin(np.radians(hours - 90)) # Peak at 180 deg (noon)
18+
summer_temp = summer_base + np.random.normal(0, 0.5, len(hours))
19+
20+
# Winter pattern: colder overall, less variation
21+
winter_base = 5 + 5 * np.sin(np.radians(hours - 90)) # Peak at 180 deg (noon)
22+
winter_temp = winter_base + np.random.normal(0, 0.3, len(hours))
23+
24+
# Close the loop by appending the first value
25+
hours_closed = np.append(hours, hours[0])
26+
summer_closed = np.append(summer_temp, summer_temp[0])
27+
winter_closed = np.append(winter_temp, winter_temp[0])
28+
29+
# Create figure
30+
fig = go.Figure()
31+
32+
# Summer line
33+
fig.add_trace(
34+
go.Scatterpolar(
35+
r=summer_closed,
36+
theta=hours_closed,
37+
mode="lines+markers",
38+
name="Summer",
39+
line=dict(color="#FFD43B", width=4),
40+
marker=dict(size=10, color="#FFD43B"),
41+
hovertemplate="Hour: %{theta}°<br>Temp: %{r:.1f}°C<extra>Summer</extra>",
42+
)
43+
)
44+
45+
# Winter line
46+
fig.add_trace(
47+
go.Scatterpolar(
48+
r=winter_closed,
49+
theta=hours_closed,
50+
mode="lines+markers",
51+
name="Winter",
52+
line=dict(color="#306998", width=4),
53+
marker=dict(size=10, color="#306998"),
54+
hovertemplate="Hour: %{theta}°<br>Temp: %{r:.1f}°C<extra>Winter</extra>",
55+
)
56+
)
57+
58+
# Layout
59+
fig.update_layout(
60+
title=dict(
61+
text="Hourly Temperature Pattern · polar-line · plotly · pyplots.ai",
62+
font=dict(size=28),
63+
x=0.5,
64+
xanchor="center",
65+
),
66+
polar=dict(
67+
radialaxis=dict(
68+
visible=True,
69+
range=[0, 35],
70+
tickfont=dict(size=18),
71+
title=dict(text="Temperature (°C)", font=dict(size=20)),
72+
gridcolor="rgba(0,0,0,0.2)",
73+
ticksuffix="°C",
74+
),
75+
angularaxis=dict(
76+
tickfont=dict(size=16),
77+
direction="clockwise",
78+
rotation=90, # Start from top (midnight)
79+
tickmode="array",
80+
tickvals=list(range(0, 360, 15)),
81+
ticktext=hour_labels,
82+
gridcolor="rgba(0,0,0,0.2)",
83+
),
84+
bgcolor="rgba(255,255,255,0.9)",
85+
),
86+
legend=dict(
87+
font=dict(size=20), x=1.05, y=0.5, bgcolor="rgba(255,255,255,0.8)", bordercolor="rgba(0,0,0,0.3)", borderwidth=1
88+
),
89+
template="plotly_white",
90+
margin=dict(l=80, r=150, t=100, b=80),
91+
)
92+
93+
# Save outputs
94+
fig.write_image("plot.png", width=1600, height=900, scale=3)
95+
fig.write_html("plot.html", include_plotlyjs="cdn")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library: plotly
2+
specification_id: polar-line
3+
created: '2025-12-30T16:30:10Z'
4+
updated: '2025-12-30T16:38:46Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20601054802
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-line/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/polar-line/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/polar-line/plotly/plot.html
13+
quality_score: 94
14+
review:
15+
strengths:
16+
- 'Excellent data choice: hourly temperature pattern is a perfect real-world use
17+
case for polar plots, demonstrating cyclical data visualization'
18+
- 'Proper loop closure: appending first value to close the polar shape is correctly
19+
implemented'
20+
- 'Good visual contrast: yellow vs dark blue colors are highly distinguishable and
21+
colorblind-safe'
22+
- 'Appropriate sizing: line width=4 and marker size=10 are well-suited for the data
23+
density'
24+
- Custom hover templates enhance interactivity
25+
weaknesses:
26+
- The radial axis has both a title Temperature (°C) and ticksuffix=°C, creating
27+
slight redundancy in the center area
28+
- Could leverage more Plotly-specific features like fill=toself for area between
29+
lines or animation frames

0 commit comments

Comments
 (0)