|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | line-timeseries: Time Series Line Plot |
3 | | -Library: seaborn 0.13.2 | Python 3.13.11 |
4 | | -Quality: 92/100 | Created: 2025-12-26 |
| 3 | +Library: seaborn 0.13.2 | Python 3.13.13 |
| 4 | +Quality: 88/100 | Updated: 2026-05-09 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import matplotlib.dates as mdates |
8 | 10 | import matplotlib.pyplot as plt |
9 | 11 | import numpy as np |
10 | 12 | import pandas as pd |
11 | 13 | import seaborn as sns |
12 | 14 |
|
13 | 15 |
|
| 16 | +# Theme tokens |
| 17 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 18 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 19 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 20 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 21 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 22 | +BRAND = "#009E73" # Okabe-Ito position 1 |
| 23 | + |
| 24 | +# Theme-adaptive seaborn configuration |
| 25 | +sns.set_theme( |
| 26 | + style="ticks", |
| 27 | + rc={ |
| 28 | + "figure.facecolor": PAGE_BG, |
| 29 | + "axes.facecolor": PAGE_BG, |
| 30 | + "axes.edgecolor": INK_SOFT, |
| 31 | + "axes.labelcolor": INK, |
| 32 | + "text.color": INK, |
| 33 | + "xtick.color": INK_SOFT, |
| 34 | + "ytick.color": INK_SOFT, |
| 35 | + "grid.color": INK, |
| 36 | + "grid.alpha": 0.15, |
| 37 | + "legend.facecolor": ELEVATED_BG, |
| 38 | + "legend.edgecolor": INK_SOFT, |
| 39 | + }, |
| 40 | +) |
| 41 | + |
14 | 42 | # Data: Daily temperature readings over 3 months |
15 | 43 | np.random.seed(42) |
16 | 44 | dates = pd.date_range(start="2024-01-01", periods=90, freq="D") |
17 | 45 |
|
18 | | -# Create realistic temperature pattern with seasonal variation and noise |
19 | 46 | day_of_year = np.arange(90) |
20 | | -base_temp = 5 + 10 * np.sin(2 * np.pi * (day_of_year + 10) / 365) # Seasonal trend |
| 47 | +base_temp = 5 + 10 * np.sin(2 * np.pi * (day_of_year + 10) / 365) |
21 | 48 | noise = np.random.randn(90) * 3 |
22 | 49 | temperature = base_temp + noise |
23 | 50 |
|
24 | 51 | df = pd.DataFrame({"Date": dates, "Temperature (°C)": temperature}) |
25 | 52 |
|
26 | | -# Create plot |
27 | | -fig, ax = plt.subplots(figsize=(16, 9)) |
| 53 | +# Plot |
| 54 | +fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG) |
28 | 55 |
|
29 | | -sns.lineplot(data=df, x="Date", y="Temperature (°C)", color="#306998", linewidth=3, ax=ax) |
| 56 | +sns.lineplot(data=df, x="Date", y="Temperature (°C)", color=BRAND, linewidth=3, ax=ax, errorbar=("ci", 95)) |
30 | 57 |
|
31 | | -# Style adjustments for large canvas |
32 | | -ax.set_xlabel("Date", fontsize=20) |
33 | | -ax.set_ylabel("Temperature (°C)", fontsize=20) |
34 | | -ax.set_title("line-timeseries · seaborn · pyplots.ai", fontsize=24) |
35 | | -ax.tick_params(axis="both", labelsize=16) |
| 58 | +# Style |
| 59 | +ax.set_xlabel("Date", fontsize=20, color=INK) |
| 60 | +ax.set_ylabel("Temperature (°C)", fontsize=20, color=INK) |
| 61 | +ax.set_title("line-timeseries · seaborn · anyplot.ai", fontsize=24, fontweight="medium", color=INK) |
| 62 | +ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT) |
36 | 63 |
|
37 | | -# Smart date formatting for months |
| 64 | +# Smart date formatting |
38 | 65 | ax.xaxis.set_major_locator(mdates.MonthLocator()) |
39 | 66 | ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %Y")) |
40 | 67 | ax.xaxis.set_minor_locator(mdates.WeekdayLocator(byweekday=mdates.MO)) |
41 | 68 |
|
42 | 69 | # Rotate labels to prevent overlap |
43 | 70 | plt.setp(ax.get_xticklabels(), rotation=45, ha="right") |
44 | 71 |
|
45 | | -# Grid for readability |
46 | | -ax.grid(True, alpha=0.3, linestyle="--") |
| 72 | +# Grid on both axes for readability |
| 73 | +ax.grid(True, alpha=0.15, linewidth=0.8, color=INK) |
| 74 | + |
| 75 | +# Remove top and right spines |
| 76 | +ax.spines["top"].set_visible(False) |
| 77 | +ax.spines["right"].set_visible(False) |
| 78 | +for spine in ["left", "bottom"]: |
| 79 | + ax.spines[spine].set_color(INK_SOFT) |
47 | 80 |
|
48 | 81 | plt.tight_layout() |
49 | | -plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
| 82 | +plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG) |
0 commit comments