Skip to content

Commit f63acfe

Browse files
committed
feat: Created area plot. Write test case of area plot. Updated md file
1 parent fd3847f commit f63acfe

File tree

5 files changed

+2599
-0
lines changed

5 files changed

+2599
-0
lines changed

docs/analysis_modules.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,52 @@ line.plot(
5353
)
5454
```
5555

56+
### **Area Plot**
57+
58+
<div class="clear" markdown>
59+
60+
![Area Plot](assets/images/analysis_modules/plots/area.svg){ align=right loading=lazy width="50%"}
61+
62+
Area plots are useful for visualizing **cumulative** trends, showing **relative contributions**, and comparing
63+
**multiple data series over time**. They are often used for:
64+
65+
- Visualizing **stacked** contributions (e.g., market share over time)
66+
- Comparing **cumulative** sales or revenue
67+
- Showing **growth trends** across multiple categories
68+
69+
Similar to line plots, **area plots** can display time-series data, but they emphasize the **area under the curve**, making them ideal for tracking proportions and cumulative metrics.
70+
71+
</div>
72+
73+
Example:
74+
75+
```python
76+
import pandas as pd
77+
from pyretailscience.plots import area
78+
79+
periods = 6
80+
rng = np.random.default_rng(42)
81+
data = {
82+
"transaction_date": np.repeat(pd.date_range("2023-01-01", periods=periods, freq="M"), 3),
83+
"unit_spend": rng.integers(1, 6, size=3 * periods),
84+
"category": ["Jeans", "Shoes", "Dresses"] * periods,
85+
}
86+
df = pd.DataFrame(data)
87+
df_pivoted = df.pivot(index="transaction_date", columns="category", values="unit_spend").reset_index()
88+
df_pivoted["category"] = df["category"]
89+
90+
area.plot(
91+
df=df_pivoted,
92+
value_col=["Jeans", "Dresses", "Shoes"],
93+
x_label="Date",
94+
y_label="Sales",
95+
title="Sales Trends by Product Category (Area Plot)",
96+
x_col="transaction_date",
97+
source_text="Source: PyRetailScience - 2024",
98+
move_legend_outside=True,
99+
)
100+
```
101+
56102
### Histogram Plot
57103

58104
<div class="clear" markdown>

docs/api/plots/area.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Area Plot
2+
3+
::: pyretailscience.plots.area

0 commit comments

Comments
 (0)