|
1 | | -""" anyplot.ai |
| 1 | +"""anyplot.ai |
2 | 2 | swarm-basic: Basic Swarm Plot |
3 | 3 | Library: seaborn 0.13.2 | Python 3.13.14 |
4 | 4 | Quality: 88/100 | Updated: 2026-07-26 |
|
73 | 73 | # Plot — figsize=(8, 4.5) @ dpi=400 → 3200×1800 (see prompts/library/seaborn.md "Canvas") |
74 | 74 | fig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG) |
75 | 75 |
|
| 76 | +# Distribution silhouette — subtle violin outline behind each swarm for density |
| 77 | +# context beyond the raw points (drawn first so the swarm layers on top) |
| 78 | +sns.violinplot( |
| 79 | + data=df, |
| 80 | + x="Condition", |
| 81 | + y="Reaction Time", |
| 82 | + hue="Condition", |
| 83 | + palette=IMPRINT_PALETTE, |
| 84 | + fill=False, |
| 85 | + inner=None, |
| 86 | + cut=0, |
| 87 | + width=0.7, |
| 88 | + linewidth=1.3, |
| 89 | + alpha=0.35, |
| 90 | + legend=False, |
| 91 | + ax=ax, |
| 92 | +) |
| 93 | + |
76 | 94 | sns.swarmplot( |
77 | 95 | data=df, |
78 | 96 | x="Condition", |
|
87 | 105 | legend=False, |
88 | 106 | ) |
89 | 107 |
|
90 | | -# Median markers — theme-adaptive diamond focal points |
| 108 | +# Median markers — hollow diamonds so the focal point reads clearly without |
| 109 | +# swallowing the underlying points in dense categories (Distraction, Fatigue) |
91 | 110 | medians = df.groupby("Condition")["Reaction Time"].median() |
92 | 111 | for i, condition in enumerate(conditions): |
93 | | - ax.scatter(i, medians[condition], marker="D", s=55, color=INK, edgecolor=PAGE_BG, linewidth=1.2, zorder=10) |
94 | | -ax.scatter([], [], marker="D", s=45, color=INK, edgecolor=PAGE_BG, linewidth=1.2, label="Median") |
| 112 | + ax.scatter(i, medians[condition], marker="D", s=70, facecolor="none", edgecolor=INK, linewidth=1.8, zorder=10) |
| 113 | +ax.scatter([], [], marker="D", s=55, facecolor="none", edgecolor=INK, linewidth=1.8, label="Median") |
95 | 114 |
|
96 | 115 | # Style |
97 | 116 | ax.set_xlabel("Experimental Condition", fontsize=10) |
98 | 117 | ax.set_ylabel("Reaction Time (ms)", fontsize=10) |
99 | 118 | ax.set_title("swarm-basic · python · seaborn · anyplot.ai", fontsize=12, fontweight="medium") |
| 119 | +# Sample size folded into each tick label — quick n context without crowding the plot area |
| 120 | +ax.set_xticks(range(len(conditions))) |
| 121 | +ax.set_xticklabels([f"{c}\n(n={n})" for c, n in zip(conditions, n_per_condition, strict=True)]) |
100 | 122 | ax.tick_params(axis="both", labelsize=8) |
101 | 123 | ax.yaxis.grid(True, alpha=0.15, linewidth=0.8) |
102 | 124 | ax.set_ylim(230, 780) |
103 | 125 | ax.legend(fontsize=8, loc="upper right") |
104 | 126 | sns.despine(ax=ax) |
| 127 | +fig.tight_layout(pad=1.2) |
105 | 128 |
|
106 | 129 | # Save |
107 | 130 | plt.savefig(f"plot-{THEME}.png", dpi=400, facecolor=PAGE_BG) |
0 commit comments