Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 39 additions & 28 deletions plots/rose-basic/implementations/python/plotly.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,75 @@
""" pyplots.ai
""" anyplot.ai
rose-basic: Basic Rose Chart
Library: plotly 6.5.0 | Python 3.13.11
Quality: 91/100 | Created: 2025-12-23
Library: plotly 6.7.0 | Python 3.13.13
Quality: 90/100 | Updated: 2026-04-30
"""

import os

import plotly.graph_objects as go


# Data - Monthly rainfall (mm) showing seasonal pattern
# Theme tokens
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
GRID = "rgba(26,26,23,0.10)" if THEME == "light" else "rgba(240,239,232,0.10)"

# Data - Monthly rainfall (mm) showing pronounced seasonal pattern
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
rainfall = [78, 62, 55, 48, 42, 38, 35, 40, 52, 68, 82, 85]
rainfall = [92, 74, 60, 45, 32, 18, 12, 22, 48, 75, 98, 105]

# Create the rose chart using barpolar
# Using month names directly as theta (categorical) for proper label placement
# Plot
fig = go.Figure()

fig.add_trace(
go.Barpolar(
r=rainfall,
theta=months,
width=0.9, # Slight gap between bars for visual clarity
width=0.9,
marker={
"color": rainfall,
"colorscale": [[0, "#FFD43B"], [1, "#306998"]], # Python Yellow to Blue
"line": {"color": "white", "width": 2},
"cmin": min(rainfall),
"colorscale": "viridis",
"line": {"color": PAGE_BG, "width": 2},
"cmin": 0,
"cmax": max(rainfall),
},
hovertemplate="<b>%{theta}</b><br>Rainfall: %{r} mm<extra></extra>",
)
)

# Update layout for 4800x2700 px output
fig.update_layout(
title={"text": "rose-basic · plotly · pyplots.ai", "font": {"size": 48}, "x": 0.5, "xanchor": "center"},
template="plotly_white",
title={
"text": "rose-basic · plotly · anyplot.ai",
"font": {"size": 48, "color": INK},
"x": 0.5,
"xanchor": "center",
},
paper_bgcolor=PAGE_BG,
polar={
"bgcolor": PAGE_BG,
"angularaxis": {
"tickfont": {"size": 28},
"tickfont": {"size": 28, "color": INK_SOFT},
"direction": "clockwise",
"rotation": 90, # Start at top (12 o'clock)
"gridcolor": "rgba(0,0,0,0.1)",
"linecolor": "rgba(0,0,0,0.3)",
"rotation": 90,
"gridcolor": GRID,
"linecolor": INK_SOFT,
},
"radialaxis": {
"tickfont": {"size": 22},
"gridcolor": "rgba(0,0,0,0.15)",
"linecolor": "rgba(0,0,0,0.3)",
"tickfont": {"size": 22, "color": INK_SOFT},
"gridcolor": GRID,
"linecolor": INK_SOFT,
"ticksuffix": " mm",
"angle": 45,
"dtick": 20,
"dtick": 25,
},
"bgcolor": "white",
},
showlegend=False,
margin={"l": 100, "r": 100, "t": 150, "b": 100},
)

# Save as PNG (4800 x 2700 px)
fig.write_image("plot.png", width=1600, height=900, scale=3)

# Save interactive HTML version
fig.write_html("plot.html", include_plotlyjs="cdn")
# Save
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")
Loading
Loading