Skip to content

Commit 20e5f26

Browse files
feat(plotly): implement rose-basic (#5594)
## Implementation: `rose-basic` - python/plotly Implements the **python/plotly** version of `rose-basic`. **File:** `plots/rose-basic/implementations/python/plotly.py` **Parent Issue:** #1003 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25151743773)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 079fdbe commit 20e5f26

2 files changed

Lines changed: 201 additions & 159 deletions

File tree

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,75 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
rose-basic: Basic Rose Chart
3-
Library: plotly 6.5.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: plotly 6.7.0 | Python 3.13.13
4+
Quality: 90/100 | Updated: 2026-04-30
55
"""
66

7+
import os
8+
79
import plotly.graph_objects as go
810

911

10-
# Data - Monthly rainfall (mm) showing seasonal pattern
12+
# Theme tokens
13+
THEME = os.getenv("ANYPLOT_THEME", "light")
14+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
15+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
16+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
17+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
18+
GRID = "rgba(26,26,23,0.10)" if THEME == "light" else "rgba(240,239,232,0.10)"
19+
20+
# Data - Monthly rainfall (mm) showing pronounced seasonal pattern
1121
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
12-
rainfall = [78, 62, 55, 48, 42, 38, 35, 40, 52, 68, 82, 85]
22+
rainfall = [92, 74, 60, 45, 32, 18, 12, 22, 48, 75, 98, 105]
1323

14-
# Create the rose chart using barpolar
15-
# Using month names directly as theta (categorical) for proper label placement
24+
# Plot
1625
fig = go.Figure()
1726

1827
fig.add_trace(
1928
go.Barpolar(
2029
r=rainfall,
2130
theta=months,
22-
width=0.9, # Slight gap between bars for visual clarity
31+
width=0.9,
2332
marker={
2433
"color": rainfall,
25-
"colorscale": [[0, "#FFD43B"], [1, "#306998"]], # Python Yellow to Blue
26-
"line": {"color": "white", "width": 2},
27-
"cmin": min(rainfall),
34+
"colorscale": "viridis",
35+
"line": {"color": PAGE_BG, "width": 2},
36+
"cmin": 0,
2837
"cmax": max(rainfall),
2938
},
3039
hovertemplate="<b>%{theta}</b><br>Rainfall: %{r} mm<extra></extra>",
3140
)
3241
)
3342

34-
# Update layout for 4800x2700 px output
3543
fig.update_layout(
36-
title={"text": "rose-basic · plotly · pyplots.ai", "font": {"size": 48}, "x": 0.5, "xanchor": "center"},
37-
template="plotly_white",
44+
title={
45+
"text": "rose-basic · plotly · anyplot.ai",
46+
"font": {"size": 48, "color": INK},
47+
"x": 0.5,
48+
"xanchor": "center",
49+
},
50+
paper_bgcolor=PAGE_BG,
3851
polar={
52+
"bgcolor": PAGE_BG,
3953
"angularaxis": {
40-
"tickfont": {"size": 28},
54+
"tickfont": {"size": 28, "color": INK_SOFT},
4155
"direction": "clockwise",
42-
"rotation": 90, # Start at top (12 o'clock)
43-
"gridcolor": "rgba(0,0,0,0.1)",
44-
"linecolor": "rgba(0,0,0,0.3)",
56+
"rotation": 90,
57+
"gridcolor": GRID,
58+
"linecolor": INK_SOFT,
4559
},
4660
"radialaxis": {
47-
"tickfont": {"size": 22},
48-
"gridcolor": "rgba(0,0,0,0.15)",
49-
"linecolor": "rgba(0,0,0,0.3)",
61+
"tickfont": {"size": 22, "color": INK_SOFT},
62+
"gridcolor": GRID,
63+
"linecolor": INK_SOFT,
5064
"ticksuffix": " mm",
5165
"angle": 45,
52-
"dtick": 20,
66+
"dtick": 25,
5367
},
54-
"bgcolor": "white",
5568
},
5669
showlegend=False,
5770
margin={"l": 100, "r": 100, "t": 150, "b": 100},
5871
)
5972

60-
# Save as PNG (4800 x 2700 px)
61-
fig.write_image("plot.png", width=1600, height=900, scale=3)
62-
63-
# Save interactive HTML version
64-
fig.write_html("plot.html", include_plotlyjs="cdn")
73+
# Save
74+
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
75+
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")

0 commit comments

Comments
 (0)