-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathletsplot.py
More file actions
75 lines (65 loc) · 2.27 KB
/
letsplot.py
File metadata and controls
75 lines (65 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
""" anyplot.ai
polar-bar: Polar Bar Chart (Wind Rose)
Library: letsplot 4.9.0 | Python 3.13.13
Quality: 92/100 | Updated: 2026-05-13
"""
import os
import numpy as np
import pandas as pd
from lets_plot import (
LetsPlot,
aes,
coord_polar,
element_line,
element_rect,
element_text,
geom_bar,
ggplot,
ggsave,
ggsize,
labs,
scale_fill_manual,
scale_y_continuous,
theme,
theme_minimal,
)
LetsPlot.setup_html()
# Theme-adaptive colors
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
# Okabe-Ito palette + adaptive neutral for 8 compass directions
OKABE_ITO = ["#009E73", "#D55E00", "#0072B2", "#CC79A7", "#E69F00", "#56B4E9", "#F0E442"]
NEUTRAL = "#1A1A1A" if THEME == "light" else "#E8E8E0"
DIRECTION_COLORS = OKABE_ITO + [NEUTRAL]
# Data - Monsoon wind pattern (SW-dominant, distinct from westerlies)
directions = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
frequencies = np.array([3, 5, 6, 12, 28, 35, 6, 5])
# Create DataFrame
df = pd.DataFrame(
{"direction": pd.Categorical(directions, categories=directions, ordered=True), "frequency": frequencies}
)
# Create polar bar chart (wind rose)
plot = (
ggplot(df, aes(x="direction", y="frequency", fill="direction"))
+ geom_bar(stat="identity", color="white", size=0.5, alpha=0.85, width=0.95)
+ coord_polar(start=-np.pi / 8)
+ scale_fill_manual(values=DIRECTION_COLORS)
+ scale_y_continuous(limits=[0, None], expand=[0, 0.5])
+ labs(title="polar-bar · letsplot · anyplot.ai", x="", y="Frequency (%)")
+ theme_minimal()
+ theme(
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
panel_grid_major=element_line(color=INK_SOFT, size=0.3),
plot_title=element_text(size=24, color=INK, face="bold"),
axis_title_y=element_text(size=20, color=INK),
axis_text=element_text(size=16, color=INK_SOFT),
legend_position="none",
)
+ ggsize(1200, 1200)
)
# Save as PNG and HTML (theme-suffixed)
ggsave(plot, f"plot-{THEME}.png", scale=3, path=".")
ggsave(plot, f"plot-{THEME}.html", path=".")