Forecast Bands (Fan Chart)#
A fan chart (or forecast bands plot) shows a central forecast line with uncertainty ranges. This example uses standard deviation to simulate a confidence interval around a time-series trend.
import pandas as pd
import numpy as np
import hvplot.pandas # noqa
np.random.seed(1)
dates = pd.date_range("2024-01-01", periods=50, freq="D")
mean = np.cumsum(np.random.normal(0, 1, 50))
std = np.linspace(1.0, 2.5, 50)
df = pd.DataFrame({
'date': dates,
'mean': mean,
'upper': mean + std,
'lower': mean - std
})
band = df.hvplot.area(
x='date', y='lower', y2='upper', alpha=0.3,
color='gray', label='Uncertainty'
)
line = df.hvplot.line(x='date', y='mean', color='blue', label='Forecast')
band * line
import pandas as pd
import numpy as np
import hvplot.pandas # noqa
hvplot.extension('matplotlib')
np.random.seed(1)
dates = pd.date_range("2024-01-01", periods=50, freq="D")
mean = np.cumsum(np.random.normal(0, 1, 50))
std = np.linspace(1.0, 2.5, 50)
df = pd.DataFrame({
'date': dates,
'mean': mean,
'upper': mean + std,
'lower': mean - std
})
band = df.hvplot.area(
x='date', y='lower', y2='upper', alpha=0.3,
color='gray', label='Uncertainty'
)
line = df.hvplot.line(x='date', y='mean', color='blue', label='Forecast')
band * line
This web page was generated from a Jupyter notebook and not all
interactivity will work on this website.