|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | 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 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import matplotlib.pyplot as plt |
8 | 10 | import numpy as np |
9 | 11 | import seaborn as sns |
10 | 12 |
|
11 | 13 |
|
| 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 | + |
12 | 39 | # Data: Monthly rainfall (mm) showing seasonal patterns |
13 | 40 | months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] |
14 | 41 | rainfall = [89, 72, 95, 112, 135, 168, 142, 125, 98, 76, 82, 91] |
15 | 42 |
|
16 | 43 | # Calculate angles - start at top (12 o'clock position) |
17 | 44 | n_categories = len(months) |
18 | 45 | angles = np.linspace(0, 2 * np.pi, n_categories, endpoint=False) |
19 | | - |
20 | | -# Bar width (slightly less than full segment for gaps) |
21 | 46 | width = 2 * np.pi / n_categories * 0.85 |
22 | 47 |
|
23 | 48 | # Create figure with polar projection (square format for radial plot) |
24 | 49 | fig, ax = plt.subplots(figsize=(12, 12), subplot_kw={"projection": "polar"}) |
| 50 | +fig.patch.set_facecolor(PAGE_BG) |
| 51 | +ax.set_facecolor(PAGE_BG) |
25 | 52 |
|
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:] |
28 | 55 |
|
29 | 56 | # 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) |
31 | 58 |
|
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) |
35 | 62 |
|
36 | | -# Set category labels at correct positions |
| 63 | +# Category labels |
37 | 64 | ax.set_xticks(angles) |
38 | | -ax.set_xticklabels(months, fontsize=20, fontweight="bold") |
| 65 | +ax.set_xticklabels(months, fontsize=20, fontweight="bold", color=INK) |
39 | 66 |
|
40 | | -# Configure radial gridlines and labels |
| 67 | +# Radial gridlines and labels |
41 | 68 | max_val = max(rainfall) |
42 | 69 | ax.set_ylim(0, max_val * 1.15) |
43 | 70 | 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) |
45 | 72 |
|
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) |
48 | 75 | ax.spines["polar"].set_visible(False) |
49 | 76 |
|
50 | | -# Add title with proper formatting |
| 77 | +# Title |
51 | 78 | 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 |
53 | 80 | ) |
54 | 81 |
|
55 | | -# Add value labels on each bar |
| 82 | +# Value labels on each bar |
56 | 83 | 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) |
60 | 85 |
|
61 | 86 | 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