|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | scatter-marginal: Scatter Plot with Marginal Distributions |
3 | | -Library: letsplot 4.8.2 | Python 3.13.11 |
4 | | -Quality: 90/100 | Created: 2025-12-26 |
| 3 | +Library: letsplot 4.9.0 | Python 3.13.13 |
| 4 | +Quality: 95/100 | Updated: 2026-05-09 |
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 * # noqa: F403 |
|
12 | 14 |
|
13 | 15 | LetsPlot.setup_html() # noqa: F405 |
14 | 16 |
|
| 17 | +# Theme tokens |
| 18 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 19 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 20 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 21 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 22 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 23 | + |
| 24 | +BRAND = "#009E73" # Okabe-Ito position 1 |
| 25 | +ACCENT = "#D55E00" # Okabe-Ito position 2 |
| 26 | + |
15 | 27 | # Data - bivariate data with correlation |
16 | 28 | np.random.seed(42) |
17 | 29 | n = 200 |
|
24 | 36 | x_min, x_max = df["x"].min() - 0.5, df["x"].max() + 0.5 |
25 | 37 | y_min, y_max = df["y"].min() - 0.5, df["y"].max() + 0.5 |
26 | 38 |
|
27 | | -# Main scatter plot with integrated title |
| 39 | +# Main scatter plot |
28 | 40 | main_scatter = ( |
29 | 41 | ggplot(df, aes(x="x", y="y")) # noqa: F405 |
30 | | - + geom_point(color="#306998", size=4, alpha=0.65) # noqa: F405 |
| 42 | + + geom_point(color=BRAND, size=4, alpha=0.65) # noqa: F405 |
31 | 43 | + labs( # noqa: F405 |
32 | | - x="X Value", y="Y Value", title="scatter-marginal · letsplot · pyplots.ai" |
| 44 | + x="Measurement A", y="Measurement B", title="scatter-marginal · letsplot · anyplot.ai" |
33 | 45 | ) |
34 | 46 | + scale_x_continuous(limits=[x_min, x_max]) # noqa: F405 |
35 | 47 | + scale_y_continuous(limits=[y_min, y_max]) # noqa: F405 |
36 | 48 | + theme_minimal() # noqa: F405 |
37 | 49 | + theme( # noqa: F405 |
38 | | - plot_title=element_text(size=24), # noqa: F405 |
39 | | - axis_title=element_text(size=20), # noqa: F405 |
40 | | - axis_text=element_text(size=16), # noqa: F405 |
| 50 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), # noqa: F405 |
| 51 | + panel_background=element_rect(fill=PAGE_BG), # noqa: F405 |
| 52 | + panel_grid_major=element_line(color=INK_SOFT, size=0.2), # noqa: F405 |
| 53 | + plot_title=element_text(size=24, color=INK), # noqa: F405 |
| 54 | + axis_title=element_text(size=20, color=INK), # noqa: F405 |
| 55 | + axis_text=element_text(size=16, color=INK_SOFT), # noqa: F405 |
| 56 | + axis_line=element_line(color=INK_SOFT), # noqa: F405 |
41 | 57 | ) |
42 | 58 | ) |
43 | 59 |
|
|
46 | 62 | ggplot(df, aes(x="x")) # noqa: F405 |
47 | 63 | + geom_histogram( # noqa: F405 |
48 | 64 | aes(y="..density.."), # noqa: F405 |
49 | | - fill="#306998", |
50 | | - color="white", |
51 | | - alpha=0.6, |
| 65 | + fill=BRAND, |
| 66 | + color=PAGE_BG, |
| 67 | + alpha=0.5, |
52 | 68 | bins=25, |
53 | 69 | ) |
54 | | - + geom_density(color="#DC2626", size=1.5, alpha=0.8) # noqa: F405 |
| 70 | + + geom_density(color=ACCENT, size=1.5, alpha=0.8) # noqa: F405 |
55 | 71 | + scale_x_continuous(limits=[x_min, x_max]) # noqa: F405 |
56 | 72 | + theme_minimal() # noqa: F405 |
57 | 73 | + theme( # noqa: F405 |
| 74 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), # noqa: F405 |
| 75 | + panel_background=element_rect(fill=PAGE_BG), # noqa: F405 |
| 76 | + panel_grid_major=element_line(color=INK_SOFT, size=0.15), # noqa: F405 |
58 | 77 | axis_title=element_blank(), # noqa: F405 |
59 | 78 | axis_text_x=element_blank(), # noqa: F405 |
60 | 79 | axis_ticks_x=element_blank(), # noqa: F405 |
61 | | - axis_text_y=element_text(size=16), # noqa: F405 |
| 80 | + axis_text_y=element_text(size=14, color=INK_SOFT), # noqa: F405 |
| 81 | + axis_line_x=element_blank(), # noqa: F405 |
62 | 82 | ) |
63 | 83 | ) |
64 | 84 |
|
|
67 | 87 | ggplot(df, aes(x="y")) # noqa: F405 |
68 | 88 | + geom_histogram( # noqa: F405 |
69 | 89 | aes(y="..density.."), # noqa: F405 |
70 | | - fill="#306998", |
71 | | - color="white", |
72 | | - alpha=0.6, |
| 90 | + fill=BRAND, |
| 91 | + color=PAGE_BG, |
| 92 | + alpha=0.5, |
73 | 93 | bins=25, |
74 | 94 | ) |
75 | | - + geom_density(color="#DC2626", size=1.5, alpha=0.8) # noqa: F405 |
| 95 | + + geom_density(color=ACCENT, size=1.5, alpha=0.8) # noqa: F405 |
76 | 96 | + coord_flip() # noqa: F405 |
77 | 97 | + scale_x_continuous(limits=[y_min, y_max]) # noqa: F405 |
78 | 98 | + theme_minimal() # noqa: F405 |
79 | 99 | + theme( # noqa: F405 |
| 100 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), # noqa: F405 |
| 101 | + panel_background=element_rect(fill=PAGE_BG), # noqa: F405 |
| 102 | + panel_grid_major=element_line(color=INK_SOFT, size=0.15), # noqa: F405 |
80 | 103 | axis_title=element_blank(), # noqa: F405 |
81 | 104 | axis_text_y=element_blank(), # noqa: F405 |
82 | 105 | axis_ticks_y=element_blank(), # noqa: F405 |
83 | | - axis_text_x=element_text(size=16), # noqa: F405 |
84 | | - plot_margin=[0, 15, 0, 0], # noqa: F405 |
| 106 | + axis_text_x=element_text(size=14, color=INK_SOFT), # noqa: F405 |
| 107 | + axis_line_y=element_blank(), # noqa: F405 |
85 | 108 | ) |
86 | 109 | ) |
87 | 110 |
|
88 | 111 | # Combine using ggbunch |
89 | | -# Regions: (x, y, width, height) - relative coordinates |
90 | 112 | combined = ( |
91 | 113 | ggbunch( # noqa: F405 |
92 | 114 | [top_hist, main_scatter, right_hist], |
93 | 115 | [ |
94 | | - (0, 0.08, 0.76, 0.20), # Top histogram (below title space) |
95 | | - (0, 0.28, 0.76, 0.72), # Main scatter plot (with title at top) |
96 | | - (0.76, 0.28, 0.24, 0.72), # Right histogram (wider for tick labels) |
| 116 | + (0, 0.0, 0.76, 0.18), # Top histogram |
| 117 | + (0, 0.18, 0.76, 0.82), # Main scatter plot |
| 118 | + (0.76, 0.18, 0.24, 0.82), # Right histogram (aligned to bottom of main plot) |
97 | 119 | ], |
98 | 120 | ) |
99 | 121 | + ggsize(1600, 900) # noqa: F405 |
100 | 122 | ) |
101 | 123 |
|
102 | 124 | # Save as PNG (scale 3x to get 4800 x 2700 px) |
103 | | -export_ggsave(combined, filename="plot.png", path=".", scale=3) |
| 125 | +export_ggsave(combined, filename=f"plot-{THEME}.png", path=".", scale=3) |
104 | 126 |
|
105 | 127 | # Save HTML for interactive version |
106 | | -export_ggsave(combined, filename="plot.html", path=".") |
| 128 | +export_ggsave(combined, filename=f"plot-{THEME}.html", path=".") |
0 commit comments