Files

109 lines
2.7 KiB
Python
Raw Permalink Normal View History

2024-04-09 22:19:09 +02:00
# This file is part of the uutils coreutils package.
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
2022-01-31 08:27:22 +01:00
import sys
import matplotlib.pyplot as plt
import pandas as pd
2026-01-07 22:50:22 +01:00
import seaborn as sns
2022-01-31 08:27:22 +01:00
2026-01-07 23:15:37 +01:00
from graph_common import (
COLORS,
setup_theme,
apply_smoothing,
style_axes,
add_title,
style_legend,
)
2026-01-07 23:03:00 +01:00
2022-01-31 08:27:22 +01:00
d = pd.read_json(sys.argv[1], orient="index")
df = pd.DataFrame(d)
df.columns.names = ["date"]
df.index = pd.to_datetime(df.index, utc=True, format="mixed")
2022-01-31 08:27:22 +01:00
print(df)
2026-01-07 23:03:00 +01:00
# Set up modern theme
setup_theme()
2026-01-07 22:50:22 +01:00
# Create figure with better proportions and higher DPI
fig, ax = plt.subplots(figsize=(18, 9), dpi=100)
# Prepare data for Seaborn - melt to long format
2026-01-07 23:15:37 +01:00
df_plot = df[["size", "multisize"]].copy()
2026-01-07 22:50:22 +01:00
df_plot = df_plot.reset_index()
2026-01-07 23:15:37 +01:00
df_plot.columns = ["date", "size", "multisize"]
df_plot_long = df_plot.melt(
id_vars="date", var_name="binary_type", value_name="size_kb"
)
2026-01-07 22:50:22 +01:00
# Convert to numeric
2026-01-07 23:15:37 +01:00
df_plot_long["size_kb"] = pd.to_numeric(df_plot_long["size_kb"], errors="coerce")
2026-01-07 22:50:22 +01:00
# Apply smoothing using rolling average
2026-01-07 23:15:37 +01:00
df_plot_long["size_kb_smooth"] = apply_smoothing(df_plot_long, "binary_type", "size_kb")
2026-01-07 22:50:22 +01:00
2026-01-07 23:03:00 +01:00
# Use color palette from common module
2026-01-07 23:15:37 +01:00
palette = {"size": COLORS["size"], "multisize": COLORS["multisize"]}
2026-01-07 22:50:22 +01:00
# Add gradient-like area fills first
for col, color in palette.items():
if col in df_plot.columns:
2026-01-07 23:15:37 +01:00
ax.fill_between(
df_plot["date"],
0,
df_plot[col],
alpha=0.2,
color=color,
zorder=1,
linewidth=0,
)
2026-01-07 22:50:22 +01:00
# Use Seaborn's lineplot with enhanced styling and smoothed data
sns.lineplot(
data=df_plot_long,
2026-01-07 23:15:37 +01:00
x="date",
y="size_kb_smooth",
hue="binary_type",
2026-01-07 22:50:22 +01:00
palette=palette,
linewidth=4,
ax=ax,
markers=False, # Disable markers for smoother look
dashes=False,
alpha=1,
2026-01-07 23:15:37 +01:00
zorder=3,
2026-01-07 22:50:22 +01:00
)
2026-01-07 23:03:00 +01:00
# Add title and subtitle
2026-01-07 23:15:37 +01:00
add_title(
ax,
"uutils coreutils — Binary Size Evolution",
"Tracking binary size optimization and comparing build strategies",
)
2026-01-07 22:50:22 +01:00
2026-01-07 23:03:00 +01:00
# Style axes with labels and grid
2026-01-07 23:15:37 +01:00
style_axes(ax, xlabel="Date", ylabel="Size (kilobytes)")
2026-01-07 22:50:22 +01:00
2026-01-07 23:03:00 +01:00
# Style legend
2026-01-07 22:50:22 +01:00
handles, labels = ax.get_legend_handles_labels()
2026-01-07 23:15:37 +01:00
label_map = {"size": "Multiple Binaries", "multisize": "Multicall Binary (Optimized)"}
2026-01-07 22:50:22 +01:00
labels = [label_map.get(label, label) for label in labels]
2026-01-07 23:15:37 +01:00
style_legend(ax, handles, labels, ncol=1, loc="upper left")
2026-01-07 22:50:22 +01:00
# Tight layout
plt.tight_layout()
# Save with high quality
2026-01-07 23:15:37 +01:00
plt.savefig(
"size-results.svg",
format="svg",
dpi=300,
bbox_inches="tight",
facecolor="white",
edgecolor="none",
metadata={"Creator": "uutils coreutils tracking", "Title": "Binary Size Evolution"},
)