diff --git a/plots/bar-categorical/implementations/letsplot.py b/plots/bar-categorical/implementations/letsplot.py new file mode 100644 index 0000000000..49902de71f --- /dev/null +++ b/plots/bar-categorical/implementations/letsplot.py @@ -0,0 +1,44 @@ +""" pyplots.ai +bar-categorical: Categorical Count Bar Chart +Library: letsplot 4.8.2 | Python 3.13.11 +Quality: 91/100 | Created: 2025-12-30 +""" + +import numpy as np +import pandas as pd +from lets_plot import * # noqa: F403 +from lets_plot.export import ggsave as export_ggsave + + +LetsPlot.setup_html() # noqa: F405 + +# Data - raw categorical values (counts computed automatically by geom_bar) +np.random.seed(42) +categories = ["Apples", "Bananas", "Oranges", "Grapes", "Mangoes"] +weights = [0.25, 0.20, 0.22, 0.18, 0.15] +n_samples = 200 + +df = pd.DataFrame({"fruit": np.random.choice(categories, size=n_samples, p=weights)}) + +# Plot - geom_bar computes counts automatically (no stat='identity') +plot = ( + ggplot(df, aes(x="fruit")) # noqa: F405 + + geom_bar(fill="#306998", color="#1a3a54", size=0.5, alpha=0.9) # noqa: F405 + + labs( # noqa: F405 + x="Fruit Type", y="Count", title="bar-categorical · letsplot · pyplots.ai" + ) + + ggsize(1600, 900) # noqa: F405 + + theme_minimal() # noqa: F405 + + theme( # noqa: F405 + plot_title=element_text(size=24, face="bold"), # noqa: F405 + axis_title=element_text(size=20), # noqa: F405 + axis_text=element_text(size=16), # noqa: F405 + axis_text_x=element_text(angle=0), # noqa: F405 + panel_grid_major_x=element_blank(), # noqa: F405 + panel_grid_minor=element_blank(), # noqa: F405 + ) +) + +# Save as PNG (scale 3x for 4800x2700 px) and HTML +export_ggsave(plot, filename="plot.png", path=".", scale=3) +export_ggsave(plot, filename="plot.html", path=".") diff --git a/plots/bar-categorical/metadata/letsplot.yaml b/plots/bar-categorical/metadata/letsplot.yaml new file mode 100644 index 0000000000..fb6c7d812e --- /dev/null +++ b/plots/bar-categorical/metadata/letsplot.yaml @@ -0,0 +1,25 @@ +library: letsplot +specification_id: bar-categorical +created: '2025-12-30T11:24:11Z' +updated: '2025-12-30T11:32:01Z' +generated_by: claude-opus-4-5-20251101 +workflow_run: 20595340647 +issue: 0 +python_version: 3.13.11 +library_version: 4.8.2 +preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-categorical/letsplot/plot.png +preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-categorical/letsplot/plot_thumb.png +preview_html: https://storage.googleapis.com/pyplots-images/plots/bar-categorical/letsplot/plot.html +quality_score: 91 +review: + strengths: + - Clean implementation following ggplot2 grammar of graphics + - Automatic count computation using geom_bar() without stat=identity + - Well-sized text elements (24pt title, 20pt axis labels, 16pt tick text) following + library guidelines + - Good use of theme_minimal() with appropriate grid customization + - Proper figure sizing (1600x900 with scale=3 for 4800x2700 output) + weaknesses: + - Does not leverage lets-plot interactive features (tooltips, hover effects) that + distinguish it from plotnine + - Data context is generic; could use a more specific real-world scenario