|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | 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 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import plotly.graph_objects as go |
8 | 10 |
|
9 | 11 |
|
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 |
11 | 21 | 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] |
13 | 23 |
|
14 | | -# Create the rose chart using barpolar |
15 | | -# Using month names directly as theta (categorical) for proper label placement |
| 24 | +# Plot |
16 | 25 | fig = go.Figure() |
17 | 26 |
|
18 | 27 | fig.add_trace( |
19 | 28 | go.Barpolar( |
20 | 29 | r=rainfall, |
21 | 30 | theta=months, |
22 | | - width=0.9, # Slight gap between bars for visual clarity |
| 31 | + width=0.9, |
23 | 32 | marker={ |
24 | 33 | "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, |
28 | 37 | "cmax": max(rainfall), |
29 | 38 | }, |
30 | 39 | hovertemplate="<b>%{theta}</b><br>Rainfall: %{r} mm<extra></extra>", |
31 | 40 | ) |
32 | 41 | ) |
33 | 42 |
|
34 | | -# Update layout for 4800x2700 px output |
35 | 43 | 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, |
38 | 51 | polar={ |
| 52 | + "bgcolor": PAGE_BG, |
39 | 53 | "angularaxis": { |
40 | | - "tickfont": {"size": 28}, |
| 54 | + "tickfont": {"size": 28, "color": INK_SOFT}, |
41 | 55 | "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, |
45 | 59 | }, |
46 | 60 | "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, |
50 | 64 | "ticksuffix": " mm", |
51 | 65 | "angle": 45, |
52 | | - "dtick": 20, |
| 66 | + "dtick": 25, |
53 | 67 | }, |
54 | | - "bgcolor": "white", |
55 | 68 | }, |
56 | 69 | showlegend=False, |
57 | 70 | margin={"l": 100, "r": 100, "t": 150, "b": 100}, |
58 | 71 | ) |
59 | 72 |
|
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