|
7 | 7 |
|
8 | 8 | ## Plots
|
9 | 9 |
|
| 10 | +### Line Plot |
| 11 | + |
| 12 | +<div class="clear" markdown> |
| 13 | + |
| 14 | +{ 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 | + |
10 | 53 | ### Waterfall Plot
|
11 | 54 |
|
12 | 55 | <div class="clear" markdown>
|
|
0 commit comments