Period on Period Plot Gallery¶
The period on period plot is used for comparing multiple overlapping time periods from the same time series on a single chart. It's ideal for analyzing seasonal patterns, promotional campaigns, or any time-based comparisons by aligning different periods to a common starting point.
Period on period plots excel at:
- Seasonal Comparisons: Compare performance across different years or seasons
- Campaign Analysis: Overlay different promotional periods to identify patterns
- Event Impact: Compare similar time windows before/during/after events
- Pattern Recognition: Identify consistent patterns across different periods
In [ ]:
Copied!
import matplotlib.pyplot as plt
import pandas as pd
from pyretailscience.plots import period_on_period
import matplotlib.pyplot as plt
import pandas as pd
from pyretailscience.plots import period_on_period
Two Period Comparison¶
Compare two time periods using the periods parameter. This is the most common use case for period-on-period analysis.
In [ ]:
Copied!
# Create sample daily sales data
sales_data = pd.DataFrame(
{
"date": pd.date_range("2022-01-01", "2024-12-31", freq="D"),
"daily_sales": [15000 + i * 10 + (i % 7) * 2000 + (i % 30) * 500 for i in range(1096)],
},
)
# Compare two periods
periods = [
("2022-06-01", "2022-06-30"),
("2023-06-01", "2023-06-30"),
]
period_on_period.plot(
sales_data,
x_col="date",
value_col="daily_sales",
periods=periods,
title="Two Period Comparison",
figsize=(10, 6),
move_legend_outside=True,
)
plt.show()
# Create sample daily sales data
sales_data = pd.DataFrame(
{
"date": pd.date_range("2022-01-01", "2024-12-31", freq="D"),
"daily_sales": [15000 + i * 10 + (i % 7) * 2000 + (i % 30) * 500 for i in range(1096)],
},
)
# Compare two periods
periods = [
("2022-06-01", "2022-06-30"),
("2023-06-01", "2023-06-30"),
]
period_on_period.plot(
sales_data,
x_col="date",
value_col="daily_sales",
periods=periods,
title="Two Period Comparison",
figsize=(10, 6),
move_legend_outside=True,
)
plt.show()
Multiple Period Comparison¶
You can also compare more than two periods simultaneously. This allows for more comprehensive analysis across multiple time windows.
In [ ]:
Copied!
# Same sales data - compare three periods to show extended capability
periods_multiple = [
("2022-06-01", "2022-06-30"),
("2023-06-01", "2023-06-30"),
("2024-06-01", "2024-06-30"),
]
period_on_period.plot(
sales_data,
x_col="date",
value_col="daily_sales",
periods=periods_multiple,
title="Three Period Comparison",
figsize=(10, 6),
move_legend_outside=True,
)
plt.show()
# Same sales data - compare three periods to show extended capability
periods_multiple = [
("2022-06-01", "2022-06-30"),
("2023-06-01", "2023-06-30"),
("2024-06-01", "2024-06-30"),
]
period_on_period.plot(
sales_data,
x_col="date",
value_col="daily_sales",
periods=periods_multiple,
title="Three Period Comparison",
figsize=(10, 6),
move_legend_outside=True,
)
plt.show()