Skip to content

Commit c250078

Browse files
Merge branch 'main' into implementation/rose-basic/pygal
2 parents 2919938 + 7e319a5 commit c250078

6 files changed

Lines changed: 584 additions & 446 deletions

File tree

plots/rose-basic/implementations/python/matplotlib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
rose-basic: Basic Rose Chart
3-
Library: matplotlib 3.10.8 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: matplotlib 3.10.9 | Python 3.13.13
4+
Quality: 80/100 | Updated: 2026-04-30
55
"""
66

77
import matplotlib.pyplot as plt
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")
Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,87 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
rose-basic: Basic Rose Chart
3-
Library: seaborn 0.13.2 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: seaborn 0.13.2 | Python 3.13.13
4+
Quality: 82/100 | Updated: 2026-04-30
55
"""
66

7+
import os
8+
79
import matplotlib.pyplot as plt
810
import numpy as np
911
import seaborn as sns
1012

1113

14+
# Theme tokens
15+
THEME = os.getenv("ANYPLOT_THEME", "light")
16+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
17+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
18+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
19+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
20+
21+
# Apply seaborn theme with full adaptive chrome
22+
sns.set_theme(
23+
style="ticks",
24+
rc={
25+
"figure.facecolor": PAGE_BG,
26+
"axes.facecolor": PAGE_BG,
27+
"axes.edgecolor": INK_SOFT,
28+
"axes.labelcolor": INK,
29+
"text.color": INK,
30+
"xtick.color": INK_SOFT,
31+
"ytick.color": INK_SOFT,
32+
"grid.color": INK_SOFT,
33+
"grid.alpha": 0.12,
34+
"legend.facecolor": ELEVATED_BG,
35+
"legend.edgecolor": INK_SOFT,
36+
},
37+
)
38+
1239
# Data: Monthly rainfall (mm) showing seasonal patterns
1340
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
1441
rainfall = [89, 72, 95, 112, 135, 168, 142, 125, 98, 76, 82, 91]
1542

1643
# Calculate angles - start at top (12 o'clock position)
1744
n_categories = len(months)
1845
angles = np.linspace(0, 2 * np.pi, n_categories, endpoint=False)
19-
20-
# Bar width (slightly less than full segment for gaps)
2146
width = 2 * np.pi / n_categories * 0.85
2247

2348
# Create figure with polar projection (square format for radial plot)
2449
fig, ax = plt.subplots(figsize=(12, 12), subplot_kw={"projection": "polar"})
50+
fig.patch.set_facecolor(PAGE_BG)
51+
ax.set_facecolor(PAGE_BG)
2552

26-
# Use seaborn color palette - Blues gradient for rainfall theme
27-
palette = sns.color_palette("Blues", n_colors=n_categories)
53+
# Use seaborn Blues palette for sequential rainfall depth; skip lightest shades
54+
palette = sns.color_palette("Blues", n_colors=n_categories + 3)[3:]
2855

2956
# Plot bars - radius proportional to value
30-
ax.bar(angles, rainfall, width=width, bottom=0, color=palette, edgecolor="white", linewidth=2, alpha=0.9)
57+
ax.bar(angles, rainfall, width=width, bottom=0, color=palette, edgecolor=PAGE_BG, linewidth=1.5, alpha=0.92)
3158

32-
# Configure polar axis - start at top, go clockwise
33-
ax.set_theta_offset(np.pi / 2) # Start at top (12 o'clock)
34-
ax.set_theta_direction(-1) # Clockwise direction
59+
# Configure polar axis - start at top (12 o'clock), clockwise
60+
ax.set_theta_offset(np.pi / 2)
61+
ax.set_theta_direction(-1)
3562

36-
# Set category labels at correct positions
63+
# Category labels
3764
ax.set_xticks(angles)
38-
ax.set_xticklabels(months, fontsize=20, fontweight="bold")
65+
ax.set_xticklabels(months, fontsize=20, fontweight="bold", color=INK)
3966

40-
# Configure radial gridlines and labels
67+
# Radial gridlines and labels
4168
max_val = max(rainfall)
4269
ax.set_ylim(0, max_val * 1.15)
4370
ax.set_yticks([50, 100, 150])
44-
ax.set_yticklabels(["50 mm", "100 mm", "150 mm"], fontsize=14, color="#555555")
71+
ax.set_yticklabels(["50 mm", "100 mm", "150 mm"], fontsize=14, color=INK_SOFT)
4572

46-
# Style the grid
47-
ax.grid(True, alpha=0.3, linestyle="--", linewidth=1.5, color="#888888")
73+
# Grid and spine styling
74+
ax.grid(True, alpha=0.18, linestyle="--", linewidth=1.2, color=INK_SOFT)
4875
ax.spines["polar"].set_visible(False)
4976

50-
# Add title with proper formatting
77+
# Title
5178
ax.set_title(
52-
"Monthly Rainfall (mm) · rose-basic · seaborn · pyplots.ai", fontsize=24, fontweight="bold", pad=35, color="#333333"
79+
"Monthly Rainfall (mm) · rose-basic · seaborn · anyplot.ai", fontsize=24, fontweight="bold", pad=35, color=INK
5380
)
5481

55-
# Add value labels on each bar
82+
# Value labels on each bar
5683
for angle, value in zip(angles, rainfall, strict=True):
57-
# Position label just outside the bar
58-
label_radius = value + 12
59-
ax.text(angle, label_radius, f"{value}", ha="center", va="center", fontsize=14, fontweight="bold", color="#306998")
84+
ax.text(angle, value + 12, f"{value}", ha="center", va="center", fontsize=14, fontweight="bold", color=INK_SOFT)
6085

6186
plt.tight_layout()
62-
plt.savefig("plot.png", dpi=300, bbox_inches="tight", facecolor="white")
87+
plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG)

0 commit comments

Comments
 (0)