Rolling average (moving average) plot
A rolling average replaces each point with the mean of a window around it, smoothing day-to-day noise and weekly cycles so the underlying trend is visible.
When to use it
- Daily data with noise or weekday effects.
- You want the trend but still want to show the raw data faintly.
Ask for it in pltchat
Upload your file and type something like:
"daily sales as faint dots with a 7-day rolling average line"
pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.
The matplotlib code
Self-contained with example data; swap in pd.read_csv(...) or
pd.read_excel(...) for your own file.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
rng = np.random.default_rng(23)
dates = pd.date_range("2024-01-01", periods=200)
sales = 100 + 0.2 * np.arange(200) + 25 * (dates.day_of_week >= 5) + rng.normal(0, 12, 200)
s = pd.Series(sales, index=dates)
fig, ax = plt.subplots(figsize=(6.4, 4))
ax.plot(s.index, s, ".", color="gray", alpha=0.5, label="Daily")
ax.plot(s.index, s.rolling(7, center=True).mean(), lw=2, label="7-day mean")
ax.set_ylabel("Sales")
ax.legend()
fig.autofmt_xdate()
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.