Skip to content

Commit 6a0c9cd

Browse files
authored
feat: add line plot (#84)
* feat: add line plot * chore: simplify code, reuse existing functionality and add more documentation examples * chore: add tests and documentation * chore: add pytest-mock dependency * chore: create plots directory for analysis_modules * chore: improve line plot * chore: documentation improvements * chore: use 'w' as default facecolor for plots * chore: small code simplifications * chore: make warning message more consistent * chore: move legend logic to standard graph utils * chore: remove redundant parentheses * chore: place parentheses back * chore: add more tests * chore: use time_line instead of timeline * chore: make plot title and labels optional
1 parent e201fea commit 6a0c9cd

File tree

12 files changed

+2649
-36
lines changed

12 files changed

+2649
-36
lines changed

docs/analysis_modules.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,49 @@ social:
77

88
## Plots
99

10+
### Line Plot
11+
12+
<div class="clear" markdown>
13+
14+
![Image title](assets/images/analysis_modules/plots/line_plot.svg){ align=right loading=lazy width="50%"}
15+
16+
Line plots are particularly good for visualizing sequences that are ordered or sequential, but not necessarily categorical, such as:
17+
18+
- Days since an event (e.g., -2, -1, 0, 1, 2)
19+
- Months since a competitor opened
20+
- Tracking how metrics change across key events
21+
22+
They are often used to compare trends across categories, show the impact of events on performance, and visualize changes over time-like sequences.
23+
24+
Note: While this module can handle datetime values on the x-axis, the **plots.time_line** plot module has additional features that make working with datetimes easier, such as easily resampling the data to alternate time frames.
25+
26+
</div>
27+
28+
Example:
29+
30+
```python
31+
import pandas as pd
32+
from pyretailscience.plots import line
33+
34+
df = pd.DataFrame({
35+
"months_since_event": range(-5, 6),
36+
"category A": [10000, 12000, 13000, 15000, 16000, 17000, 18000, 20000, 21000, 20030, 25000],
37+
"category B": [9000, 10000, 11000, 13000, 14000, 15000, 10000, 7000, 3500, 3000, 2800],
38+
})
39+
40+
line.plot(
41+
df=df,
42+
value_col=["category A", "category B"],
43+
x_label="Months Since Event",
44+
y_label="Revenue (£)",
45+
title="Revenue Trends across Categories",
46+
x_col="months_since_event",
47+
group_col=None,
48+
source_text="Source: PyRetailScience - 2024",
49+
move_legend_outside=True,
50+
)
51+
```
52+
1053
### Waterfall Plot
1154

1255
<div class="clear" markdown>

docs/api/plots/line.md

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

0 commit comments

Comments
 (0)