|
1 | 1 | """ pyplots.ai |
2 | 2 | density-basic: Basic Density Plot |
3 | | -Library: seaborn 0.13.2 | Python 3.13.11 |
4 | | -Quality: 93/100 | Created: 2025-12-23 |
| 3 | +Library: seaborn 0.13.2 | 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 | import seaborn as sns |
10 | 10 |
|
11 | 11 |
|
12 | | -# Data - create a realistic bimodal distribution of test scores |
| 12 | +# Data - bimodal distribution of test scores |
13 | 13 | np.random.seed(42) |
14 | 14 | test_scores = np.concatenate( |
15 | 15 | [ |
16 | | - np.random.normal(72, 10, 300), # Main group centered at 72 |
17 | | - np.random.normal(88, 5, 100), # High achievers group |
| 16 | + np.random.normal(68, 8, 280), # Main group centered at 68 |
| 17 | + np.random.normal(90, 4, 120), # High achievers group |
18 | 18 | ] |
19 | 19 | ) |
20 | 20 |
|
21 | | -# Create figure |
| 21 | +# Plot |
22 | 22 | fig, ax = plt.subplots(figsize=(16, 9)) |
23 | | - |
24 | | -# Plot density curve with fill |
25 | 23 | sns.kdeplot(data=test_scores, ax=ax, fill=True, alpha=0.6, color="#306998", linewidth=3) |
26 | | - |
27 | | -# Add rug plot to show individual observations |
28 | 24 | sns.rugplot(data=test_scores, ax=ax, color="#306998", alpha=0.3, height=0.03) |
29 | 25 |
|
30 | 26 | # Style |
31 | 27 | ax.set_xlabel("Test Score (points)", fontsize=20) |
32 | 28 | ax.set_ylabel("Density", fontsize=20) |
33 | | -ax.set_title("density-basic · seaborn · pyplots.ai", fontsize=24) |
| 29 | +ax.set_title("density-basic · seaborn · pyplots.ai", fontsize=24, fontweight="medium") |
34 | 30 | ax.tick_params(axis="both", labelsize=16) |
35 | | -ax.grid(True, alpha=0.3, linestyle="--") |
| 31 | +ax.spines["top"].set_visible(False) |
| 32 | +ax.spines["right"].set_visible(False) |
| 33 | +ax.yaxis.grid(True, alpha=0.2, linewidth=0.8) |
36 | 34 |
|
37 | 35 | plt.tight_layout() |
38 | 36 | plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
0 commit comments