|
1 | 1 | """ pyplots.ai |
2 | 2 | violin-basic: Basic Violin Plot |
3 | | -Library: letsplot 4.8.1 | Python 3.13.11 |
4 | | -Quality: 91/100 | Created: 2025-12-23 |
| 3 | +Library: letsplot 4.8.2 | Python 3.14.3 |
| 4 | +Quality: /100 | Updated: 2026-02-21 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import numpy as np |
|
16 | 16 | np.random.seed(42) |
17 | 17 |
|
18 | 18 | categories = ["Engineering", "Marketing", "Sales", "Design"] |
19 | | -colors = ["#306998", "#FFD43B", "#4B8BBE", "#FFE873"] |
| 19 | +colors = ["#306998", "#E8A317", "#4B8BBE", "#2E8B57"] |
20 | 20 |
|
21 | | -# Generate realistic salary distributions per department |
22 | 21 | data = [] |
23 | 22 | distributions = { |
24 | 23 | "Engineering": {"mean": 95000, "std": 20000, "n": 200}, |
|
30 | 29 | for cat in categories: |
31 | 30 | dist = distributions[cat] |
32 | 31 | values = np.random.normal(dist["mean"], dist["std"], dist["n"]) |
33 | | - values = np.clip(values, 30000, 200000) # Realistic salary bounds |
| 32 | + values = np.clip(values, 30000, 200000) |
34 | 33 | for v in values: |
35 | 34 | data.append({"Department": cat, "Salary": v}) |
36 | 35 |
|
|
40 | 39 | plot = ( |
41 | 40 | ggplot(df, aes(x="Department", y="Salary", fill="Department")) # noqa: F405 |
42 | 41 | + geom_violin( # noqa: F405 |
43 | | - quantiles=[0.25, 0.5, 0.75], # Show quartiles including median |
44 | | - quantile_lines=True, # Draw lines at quantiles |
45 | | - size=1.5, # Border thickness |
46 | | - alpha=0.8, |
47 | | - trim=False, # Show full tails |
| 42 | + quantiles=[0.25, 0.5, 0.75], quantile_lines=True, size=1.2, alpha=0.85, trim=False, color="#2C3E50" |
48 | 43 | ) |
49 | 44 | + scale_fill_manual(values=colors) # noqa: F405 |
| 45 | + + scale_y_continuous( # noqa: F405 |
| 46 | + format="${,.0f}" |
| 47 | + ) |
50 | 48 | + labs( # noqa: F405 |
51 | | - x="Department", y="Salary ($)", title="violin-basic · lets-plot · pyplots.ai" |
| 49 | + x="Department", y="Salary", title="violin-basic \u00b7 letsplot \u00b7 pyplots.ai" |
52 | 50 | ) |
53 | 51 | + theme_minimal() # noqa: F405 |
54 | 52 | + theme( # noqa: F405 |
55 | 53 | axis_title=element_text(size=20), # noqa: F405 |
56 | 54 | axis_text=element_text(size=16), # noqa: F405 |
57 | 55 | plot_title=element_text(size=24), # noqa: F405 |
58 | | - legend_position="none", # Legend not needed, x-axis shows categories |
| 56 | + legend_position="none", |
| 57 | + panel_grid_major_x=element_blank(), # noqa: F405 |
| 58 | + axis_ticks=element_blank(), # noqa: F405 |
59 | 59 | ) |
60 | 60 | + ggsize(1600, 900) # noqa: F405 |
61 | 61 | ) |
62 | 62 |
|
63 | | -# Save PNG (scale 3x to get 4800 × 2700 px) |
| 63 | +# Save |
64 | 64 | export_ggsave(plot, filename="plot.png", path=".", scale=3) |
65 | | - |
66 | | -# Save HTML for interactive version |
67 | 65 | export_ggsave(plot, filename="plot.html", path=".") |
0 commit comments