|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | box-horizontal: Horizontal Box Plot |
3 | | -Library: letsplot 4.8.2 | Python 3.13.11 |
4 | | -Quality: 92/100 | Created: 2025-12-30 |
| 3 | +Library: letsplot 4.9.0 | Python 3.13.13 |
| 4 | +Quality: 87/100 | Updated: 2026-05-12 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import numpy as np |
8 | 10 | import pandas as pd |
9 | 11 | from lets_plot import * |
10 | 12 |
|
11 | 13 |
|
12 | 14 | LetsPlot.setup_html() |
13 | 15 |
|
14 | | -# Data - Response times by service type (realistic scenario with varied distributions) |
| 16 | +# Theme tokens |
| 17 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 18 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 19 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 20 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 21 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 22 | +BRAND = "#009E73" # Okabe-Ito position 1 |
| 23 | + |
| 24 | +# Data - Response times by service type |
15 | 25 | np.random.seed(42) |
16 | 26 |
|
17 | 27 | services = ["API Gateway", "Database Query", "Authentication", "File Storage", "Cache Lookup", "Email Service"] |
18 | 28 |
|
19 | 29 | data = [] |
20 | | -# Different distributions to showcase boxplot features (medians, spreads, outliers) |
21 | 30 | distributions = { |
22 | | - "API Gateway": (120, 40, 3), # Medium response, moderate spread, some outliers |
23 | | - "Database Query": (250, 100, 5), # Slower, high variability, more outliers |
24 | | - "Authentication": (80, 25, 2), # Fast, consistent |
25 | | - "File Storage": (300, 80, 4), # Slowest, variable |
26 | | - "Cache Lookup": (15, 8, 2), # Very fast, tight distribution |
27 | | - "Email Service": (180, 60, 6), # Medium, some outliers |
| 31 | + "API Gateway": (120, 40, 3), |
| 32 | + "Database Query": (250, 100, 5), |
| 33 | + "Authentication": (80, 25, 2), |
| 34 | + "File Storage": (300, 80, 4), |
| 35 | + "Cache Lookup": (15, 8, 2), |
| 36 | + "Email Service": (180, 60, 6), |
28 | 37 | } |
29 | 38 |
|
30 | 39 | for service in services: |
31 | 40 | mean, std, n_outliers = distributions[service] |
32 | | - # Main distribution |
33 | 41 | values = np.random.normal(mean, std, 80) |
34 | | - # Add some outliers |
35 | 42 | outliers = np.random.normal(mean + 4 * std, std / 2, n_outliers) |
36 | 43 | all_values = np.concatenate([values, outliers]) |
37 | | - all_values = np.maximum(all_values, 5) # Ensure positive values |
| 44 | + all_values = np.maximum(all_values, 5) |
38 | 45 |
|
39 | 46 | for val in all_values: |
40 | 47 | data.append({"Service": service, "Response Time (ms)": val}) |
|
45 | 52 | plot = ( |
46 | 53 | ggplot(df, aes(x="Response Time (ms)", y="Service")) |
47 | 54 | + geom_boxplot( |
48 | | - fill="#306998", color="#1a3a4f", alpha=0.7, outlier_color="#FFD43B", outlier_size=4, outlier_alpha=0.8, size=1.2 |
| 55 | + fill=BRAND, color=INK_SOFT, alpha=0.7, outlier_color=INK_SOFT, outlier_size=4, outlier_alpha=0.6, size=1.0 |
49 | 56 | ) |
50 | | - + labs(x="Response Time (ms)", y="Service Type", title="box-horizontal · letsplot · pyplots.ai") |
| 57 | + + labs(x="Response Time (ms)", y="Service Type", title="box-horizontal · letsplot · anyplot.ai") |
51 | 58 | + theme_minimal() |
52 | 59 | + theme( |
53 | | - axis_title=element_text(size=20), |
54 | | - axis_text=element_text(size=16), |
55 | | - axis_text_y=element_text(size=16), |
56 | | - plot_title=element_text(size=24), |
| 60 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
| 61 | + panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
| 62 | + axis_title=element_text(size=20, color=INK), |
| 63 | + axis_text=element_text(size=16, color=INK_SOFT), |
| 64 | + axis_text_y=element_text(size=16, color=INK_SOFT), |
| 65 | + plot_title=element_text(size=24, color=INK), |
| 66 | + panel_grid_major_x=element_line(color=INK_SOFT, size=0.2), |
57 | 67 | panel_grid_major_y=element_blank(), |
58 | 68 | panel_grid_minor=element_blank(), |
| 69 | + axis_line=element_line(color=INK_SOFT, size=0.5), |
59 | 70 | ) |
60 | 71 | + ggsize(1600, 900) |
61 | 72 | ) |
62 | 73 |
|
63 | | -# Save as PNG (scale 3x to get 4800 x 2700 px) |
64 | | -ggsave(plot, "plot.png", path=".", scale=3) |
| 74 | +# Save PNG (scale 3x to get 4800 x 2700 px) |
| 75 | +ggsave(plot, f"plot-{THEME}.png", path=".", scale=3) |
65 | 76 |
|
66 | | -# Save interactive HTML version |
67 | | -ggsave(plot, "plot.html", path=".") |
| 77 | +# Save interactive HTML |
| 78 | +ggsave(plot, f"plot-{THEME}.html", path=".") |
0 commit comments