|
1 | | -""" pyplots.ai |
| 1 | +"""pyplots.ai |
2 | 2 | band-basic: Basic Band Plot |
3 | | -Library: matplotlib 3.10.8 | Python 3.13.11 |
4 | | -Quality: 93/100 | Created: 2025-12-23 |
| 3 | +Library: matplotlib 3.10.8 | Python 3.14 |
| 4 | +Quality: /100 | Updated: 2026-02-23 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import matplotlib.pyplot as plt |
8 | 8 | import numpy as np |
9 | 9 |
|
10 | 10 |
|
11 | | -# Data - Simulating a time series with 95% confidence interval |
| 11 | +# Data - Daily temperature forecast with 95% confidence interval |
12 | 12 | np.random.seed(42) |
13 | | -x = np.linspace(0, 10, 100) |
| 13 | +days = np.arange(1, 31) |
14 | 14 |
|
15 | | -# Central trend line (sinusoidal pattern with slight upward trend) |
16 | | -y_center = 2 * np.sin(x) + 0.3 * x + 5 |
| 15 | +# Central forecast: seasonal warming pattern peaking mid-month |
| 16 | +temp_forecast = 12 + 6 * np.sin(np.pi * days / 30) + 0.1 * days |
17 | 17 |
|
18 | | -# Confidence interval that widens over time (common in forecasting) |
19 | | -uncertainty = 0.5 + 0.15 * x |
20 | | -y_lower = y_center - uncertainty |
21 | | -y_upper = y_center + uncertainty |
| 18 | +# Confidence interval widens further into the forecast (common in weather models) |
| 19 | +uncertainty = 0.8 + 0.12 * days |
| 20 | +temp_lower = temp_forecast - uncertainty |
| 21 | +temp_upper = temp_forecast + uncertainty |
22 | 22 |
|
23 | 23 | # Plot |
24 | 24 | fig, ax = plt.subplots(figsize=(16, 9)) |
25 | 25 |
|
26 | | -# Filled band (semi-transparent) |
27 | | -ax.fill_between(x, y_lower, y_upper, alpha=0.3, color="#306998", label="95% Confidence Interval") |
| 26 | +ax.fill_between(days, temp_lower, temp_upper, alpha=0.25, color="#306998", label="95% Confidence Interval") |
| 27 | +ax.plot(days, temp_forecast, color="#306998", linewidth=3, label="Forecast Mean") |
| 28 | +ax.plot(days, temp_lower, color="#306998", linewidth=1.5, linestyle="--", alpha=0.5) |
| 29 | +ax.plot(days, temp_upper, color="#306998", linewidth=1.5, linestyle="--", alpha=0.5) |
28 | 30 |
|
29 | | -# Central trend line |
30 | | -ax.plot(x, y_center, color="#306998", linewidth=3, label="Mean Trend") |
31 | | - |
32 | | -# Boundary lines (subtle) |
33 | | -ax.plot(x, y_lower, color="#306998", linewidth=1.5, linestyle="--", alpha=0.7) |
34 | | -ax.plot(x, y_upper, color="#306998", linewidth=1.5, linestyle="--", alpha=0.7) |
35 | | - |
36 | | -# Styling |
37 | | -ax.set_xlabel("Time (s)", fontsize=20) |
38 | | -ax.set_ylabel("Value", fontsize=20) |
39 | | -ax.set_title("band-basic · matplotlib · pyplots.ai", fontsize=24) |
| 31 | +# Style |
| 32 | +ax.set_xlabel("Day of Month", fontsize=20) |
| 33 | +ax.set_ylabel("Temperature (\u00b0C)", fontsize=20) |
| 34 | +ax.set_title("band-basic \u00b7 matplotlib \u00b7 pyplots.ai", fontsize=24, fontweight="medium") |
40 | 35 | ax.tick_params(axis="both", labelsize=16) |
41 | 36 | ax.legend(fontsize=16, loc="upper left") |
42 | | -ax.grid(True, alpha=0.3, linestyle="--") |
| 37 | +ax.spines["top"].set_visible(False) |
| 38 | +ax.spines["right"].set_visible(False) |
| 39 | +ax.yaxis.grid(True, alpha=0.2, linewidth=0.8) |
43 | 40 |
|
44 | 41 | plt.tight_layout() |
45 | 42 | plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
0 commit comments