Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 57 additions & 36 deletions plots/ecdf-basic/implementations/python/letsplot.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,74 @@
""" pyplots.ai
""" anyplot.ai
ecdf-basic: Basic ECDF Plot
Library: letsplot 4.8.2 | Python 3.13.11
Quality: 96/100 | Created: 2025-12-23
Library: letsplot 4.9.0 | Python 3.14.4
Quality: 87/100 | Updated: 2026-04-24
"""

import os

import numpy as np
import pandas as pd
from lets_plot import * # noqa: F403
from lets_plot.export import ggsave as export_ggsave
from lets_plot import (
LetsPlot,
aes,
element_blank,
element_line,
element_rect,
element_text,
ggplot,
ggsize,
labs,
scale_y_continuous,
stat_ecdf,
theme,
theme_minimal,
)
from lets_plot.export import ggsave


LetsPlot.setup_html()

LetsPlot.setup_html() # noqa: F405
# Theme tokens
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"
GRID = "#C9C7C1" if THEME == "light" else "#565551"
BRAND = "#009E73"

# Data - Response times (ms) from a web service
# Data — Web service response times (ms) with mixed distribution
np.random.seed(42)
response_times = np.concatenate(
[
np.random.exponential(scale=50, size=150), # Fast responses
np.random.normal(loc=200, scale=30, size=50), # Slower responses
]
[np.random.exponential(scale=50, size=150), np.random.normal(loc=200, scale=30, size=50)]
)
df = pd.DataFrame({"response_time": response_times})

# Sort data and calculate ECDF values
sorted_values = np.sort(response_times)
ecdf_values = np.arange(1, len(sorted_values) + 1) / len(sorted_values)

df = pd.DataFrame({"response_time": sorted_values, "ecdf": ecdf_values})

# Plot - ECDF as step function
# Plot — ECDF using stat_ecdf with step geometry
plot = (
ggplot(df, aes(x="response_time", y="ecdf")) # noqa: F405
+ geom_step(color="#306998", size=2) # noqa: F405
+ labs( # noqa: F405
x="Response Time (ms)", y="Cumulative Proportion", title="ecdf-basic · letsplot · pyplots.ai"
ggplot(df, aes(x="response_time"))
+ stat_ecdf(geom="step", color=BRAND, size=2)
+ labs(
x="Response Time (ms)",
y="Cumulative Proportion",
title="Web Service Response Times · ecdf-basic · letsplot · anyplot.ai",
)
+ scale_y_continuous(limits=[0, 1], breaks=[0, 0.25, 0.5, 0.75, 1.0]) # noqa: F405
+ ggsize(1600, 900) # noqa: F405
+ theme_minimal() # noqa: F405
+ theme( # noqa: F405
axis_text=element_text(size=16), # noqa: F405
axis_title=element_text(size=20), # noqa: F405
plot_title=element_text(size=24), # noqa: F405
panel_grid_major=element_line(color="#CCCCCC", size=0.5, linetype="dashed"), # noqa: F405
panel_grid_minor=element_blank(), # noqa: F405
+ scale_y_continuous(limits=[0, 1], breaks=[0, 0.25, 0.5, 0.75, 1.0])
+ ggsize(1600, 900)
+ theme_minimal()
+ theme(
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
legend_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
panel_grid_major=element_line(color=GRID, size=0.6),
panel_grid_minor=element_blank(),
axis_line=element_line(color=INK_SOFT, size=0.6),
axis_ticks=element_line(color=INK_SOFT, size=0.5),
axis_text=element_text(size=16, color=INK_SOFT),
axis_title=element_text(size=20, color=INK),
plot_title=element_text(size=24, color=INK),
)
)

# Save PNG (scale 3x to get 4800 x 2700 px)
export_ggsave(plot, filename="plot.png", path=".", scale=3)

# Save HTML for interactive version
export_ggsave(plot, filename="plot.html", path=".")
# Save
ggsave(plot, filename=f"plot-{THEME}.png", path=".", scale=3)
ggsave(plot, filename=f"plot-{THEME}.html", path=".")
Loading
Loading