|
1 | | -""" pyplots.ai |
| 1 | +"""pyplots.ai |
2 | 2 | bump-basic: Basic Bump 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.14.3 |
| 4 | +Quality: /100 | Updated: 2026-02-22 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import matplotlib.pyplot as plt |
|
10 | 10 |
|
11 | 11 |
|
12 | 12 | # Data - Sports league standings over 6 weeks |
13 | | -data = { |
14 | | - "Team": ["Lions"] * 6 + ["Tigers"] * 6 + ["Bears"] * 6 + ["Eagles"] * 6 + ["Wolves"] * 6, |
15 | | - "Week": ["Week 1", "Week 2", "Week 3", "Week 4", "Week 5", "Week 6"] * 5, |
16 | | - "Rank": [ |
17 | | - 3, |
18 | | - 2, |
19 | | - 1, |
20 | | - 1, |
21 | | - 2, |
22 | | - 1, # Lions - start mid, climb to top |
23 | | - 1, |
24 | | - 1, |
25 | | - 2, |
26 | | - 3, |
27 | | - 1, |
28 | | - 2, # Tigers - start top, fluctuate |
29 | | - 5, |
30 | | - 4, |
31 | | - 4, |
32 | | - 2, |
33 | | - 3, |
34 | | - 3, # Bears - steady climb from bottom |
35 | | - 2, |
36 | | - 3, |
37 | | - 3, |
38 | | - 4, |
39 | | - 4, |
40 | | - 5, # Eagles - gradual decline |
41 | | - 4, |
42 | | - 5, |
43 | | - 5, |
44 | | - 5, |
45 | | - 5, |
46 | | - 4, # Wolves - mostly bottom, slight recovery |
47 | | - ], |
48 | | -} |
49 | | -df = pd.DataFrame(data) |
| 13 | +teams = ["Lions", "Tigers", "Bears", "Eagles", "Wolves"] |
| 14 | +weeks = ["Week 1", "Week 2", "Week 3", "Week 4", "Week 5", "Week 6"] |
| 15 | +ranks = [ |
| 16 | + 3, |
| 17 | + 2, |
| 18 | + 1, |
| 19 | + 1, |
| 20 | + 2, |
| 21 | + 1, # Lions - start mid, climb to top |
| 22 | + 1, |
| 23 | + 1, |
| 24 | + 2, |
| 25 | + 3, |
| 26 | + 1, |
| 27 | + 2, # Tigers - start top, fluctuate |
| 28 | + 5, |
| 29 | + 4, |
| 30 | + 4, |
| 31 | + 2, |
| 32 | + 3, |
| 33 | + 3, # Bears - steady climb from bottom |
| 34 | + 2, |
| 35 | + 3, |
| 36 | + 3, |
| 37 | + 4, |
| 38 | + 4, |
| 39 | + 5, # Eagles - gradual decline |
| 40 | + 4, |
| 41 | + 5, |
| 42 | + 5, |
| 43 | + 5, |
| 44 | + 5, |
| 45 | + 4, # Wolves - mostly bottom, slight recovery |
| 46 | +] |
| 47 | +df = pd.DataFrame( |
| 48 | + {"Team": [team for team in teams for _ in weeks], "Competition Week": weeks * len(teams), "League Position": ranks} |
| 49 | +) |
50 | 50 |
|
51 | | -# Colors for each team - Python Blue first, then distinct colorblind-safe colors |
| 51 | +# Palette - Python Blue first, then distinct colorblind-safe colors |
52 | 52 | palette = ["#306998", "#FFD43B", "#E74C3C", "#2ECC71", "#9B59B6"] |
53 | 53 |
|
54 | | -# Create plot |
| 54 | +# Plot |
| 55 | +sns.set_theme( |
| 56 | + style="whitegrid", |
| 57 | + rc={"axes.spines.top": False, "axes.spines.right": False, "grid.linestyle": "--", "grid.alpha": 0.2}, |
| 58 | +) |
55 | 59 | fig, ax = plt.subplots(figsize=(16, 9)) |
56 | 60 |
|
57 | | -sns.lineplot(data=df, x="Week", y="Rank", hue="Team", marker="o", markersize=18, linewidth=4, palette=palette, ax=ax) |
| 61 | +sns.lineplot( |
| 62 | + data=df, |
| 63 | + x="Competition Week", |
| 64 | + y="League Position", |
| 65 | + hue="Team", |
| 66 | + style="Team", |
| 67 | + markers=True, |
| 68 | + dashes=False, |
| 69 | + markersize=18, |
| 70 | + linewidth=4, |
| 71 | + palette=palette, |
| 72 | + sort=False, |
| 73 | + ax=ax, |
| 74 | +) |
58 | 75 |
|
59 | 76 | # Invert y-axis so rank 1 is at top |
60 | 77 | ax.invert_yaxis() |
61 | | - |
62 | | -# Set y-axis ticks to integer ranks only |
63 | 78 | ax.set_yticks([1, 2, 3, 4, 5]) |
| 79 | +ax.xaxis.grid(False) |
64 | 80 |
|
65 | | -# Styling |
66 | | -ax.set_xlabel("Week", fontsize=20) |
67 | | -ax.set_ylabel("Rank", fontsize=20) |
68 | | -ax.set_title("bump-basic · seaborn · pyplots.ai", fontsize=24) |
| 81 | +# Style |
| 82 | +ax.set_xlabel("Competition Week", fontsize=20) |
| 83 | +ax.set_ylabel("League Position", fontsize=20) |
| 84 | +ax.set_title("bump-basic · seaborn · pyplots.ai", fontsize=24, fontweight="medium") |
69 | 85 | ax.tick_params(axis="both", labelsize=16) |
70 | | -ax.grid(True, alpha=0.3, linestyle="--") |
71 | 86 |
|
72 | | -# Legend styling - placed outside plot area |
73 | | -ax.legend(title="Team", fontsize=14, title_fontsize=16, loc="center left", bbox_to_anchor=(1, 0.5)) |
| 87 | +# Legend |
| 88 | +ax.legend(title="Team", fontsize=14, title_fontsize=16, loc="center left", bbox_to_anchor=(1, 0.5), frameon=False) |
74 | 89 |
|
75 | 90 | plt.tight_layout() |
76 | 91 | plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
0 commit comments