|
11 | 11 | LetsPlot.setup_html() # noqa: F405 |
12 | 12 |
|
13 | 13 | # Data - Product sales by category |
14 | | -categories = ["Electronics", "Clothing", "Home & Garden", "Sports", "Books", "Toys", "Food & Beverage"] |
15 | | -values = [45200, 32800, 28500, 21300, 18700, 15400, 12100] |
| 14 | +categories = ["Electronics", "Clothing", "Home & Garden", "Sports", "Books", "Toys"] |
| 15 | +values = [45200, 32800, 28500, 21300, 18900, 15600] |
16 | 16 |
|
17 | 17 | df = pd.DataFrame({"category": categories, "value": values}) |
18 | 18 |
|
| 19 | +# Preserve category order |
| 20 | +df["category"] = pd.Categorical(df["category"], categories=categories, ordered=True) |
| 21 | + |
19 | 22 | # Plot |
20 | 23 | plot = ( |
21 | 24 | ggplot(df, aes(x="category", y="value")) # noqa: F405 |
22 | | - + geom_bar(stat="identity", fill="#306998", width=0.7) # noqa: F405 |
| 25 | + + geom_bar(stat="identity", fill="#306998", width=0.6) # noqa: F405 |
| 26 | + + geom_text( # noqa: F405 |
| 27 | + aes(label="value"), # noqa: F405 |
| 28 | + position=position_nudge(y=1500), # noqa: F405 |
| 29 | + size=14, |
| 30 | + label_format="${,}", |
| 31 | + ) |
23 | 32 | + labs(x="Product Category", y="Sales ($)", title="Product Sales by Category") # noqa: F405 |
| 33 | + + scale_y_continuous(limits=[0, 55000]) # noqa: F405 |
24 | 34 | + ggsize(1600, 900) # noqa: F405 |
25 | 35 | + theme_minimal() # noqa: F405 |
26 | 36 | + theme( # noqa: F405 |
|
0 commit comments