> ## Documentation Index
> Fetch the complete documentation index at: https://nixtlaverse.nixtla.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Plotting

> Time series visualizations

### `plot_series`

```python theme={null}
plot_series(df=None, forecasts_df=None, ids=None, plot_random=True, max_ids=8, models=None, level=None, max_insample_length=None, plot_anomalies=False, engine='matplotlib', palette=None, id_col='unique_id', time_col='ds', target_col='y', seed=0, resampler_kwargs=None, ax=None)
```

Plot forecasts and insample values.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `df` | `pandas or polars DataFrame` | DataFrame with columns \[`id_col`, `time_col`, `target_col`]. Defaults to None. | `None` |
| `forecasts_df` | `pandas or polars DataFrame` | DataFrame with columns \[`id_col`, `time_col`] and models. Defaults to None. | `None` |
| `ids` | `list of str` | Time Series to plot. If None, time series are selected randomly. Defaults to None. | `None` |
| `plot_random` | `bool` | Select time series to plot randomly. Defaults to True. | `True` |
| `max_ids` | `int` | Maximum number of ids to plot. Defaults to 8. | `8` |
| `models` | `list of str` | Models to plot. Defaults to None. | `None` |
| `level` | `list of float` | Prediction intervals to plot. Defaults to None. | `None` |
| `max_insample_length` | `int` | Maximum number of train/insample observations to be plotted. Defaults to None. | `None` |
| `plot_anomalies` | `bool` | Plot anomalies for each prediction interval. Defaults to False. | `False` |
| `engine` | `str` | Library used to plot. 'plotly', 'plotly-resampler' or 'matplotlib'. Defaults to 'matplotlib'. | `'matplotlib'` |
| `palette` | `str` | Name of the matplotlib colormap to use for the plots. If None, uses the current style. Defaults to None. | `None` |
| `id_col` | `str` | Column that identifies each serie. Defaults to 'unique\_id'. | `'unique_id'` |
| `time_col` | `str` | Column that identifies each timestep, its values can be timestamps or integers. Defaults to 'ds'. | `'ds'` |
| `target_col` | `str` | Column that contains the target. Defaults to 'y'. | `'y'` |
| `seed` | `int` | Seed used for the random number generator. Only used if plot\_random is True. Defaults to 0. | `0` |
| `resampler_kwargs` | `dict` | Keyword arguments to be passed to plotly-resampler constructor. For further customization ("show\_dash") call the method, store the plotting object and add the extra arguments to its `show_dash` method. Defaults to None. | `None` |
| `ax` | `matplotlib axes, array of matplotlib axes or plotly Figure` | Object where plots will be added. Defaults to None. | `None` |

**Returns:**

| Type | Description |
| - | - |
| matplotlib or plotly figure: Plot's figure | |

```python theme={null}
from utilsforecast.data import generate_series
```

```python theme={null}
level = [80, 95]
series = generate_series(4, freq='D', equal_ends=True, with_trend=True, n_models=2, level=level)
test_pd = series.groupby('unique_id', observed=True).tail(10).copy()
train_pd = series.drop(test_pd.index)
```

```python theme={null}
plt.style.use('ggplot')
fig = plot_series(
    train_pd,
    forecasts_df=test_pd,
    ids=[0, 3],
    plot_random=False,
    level=level,    
    max_insample_length=50,
    engine='matplotlib',
    plot_anomalies=True,
)
fig.savefig('imgs/plotting.png', bbox_inches='tight')
```

![plot](https://raw.githubusercontent.com/Nixtla/utilsforecast/refs/heads/main/docs/mintlify/imgs/plotting.png)


## Related topics

- [Probabilistic Forecasting | NeuralForecast](https://nixtlaverse.nixtla.io/neuralforecast/docs/tutorials/uncertainty_quantification.html.md)
- [Statistical, Machine Learning and Neural Forecasting methods| NeuralForecast](https://nixtlaverse.nixtla.io/neuralforecast/docs/tutorials/comparing_methods.html.md)
- [Statistical, Machine Learning and Neural Forecasting methods | StatsForecast](https://nixtlaverse.nixtla.io/statsforecast/docs/tutorials/statisticalneuralmethods.html.md)
- [Temporal Aggregation (Tourism)](https://nixtlaverse.nixtla.io/hierarchicalforecast/examples/australiandomestictourismtemporal.html.md)
- [Explainability for Deep Learning Forecasting Models](https://nixtlaverse.nixtla.io/neuralforecast/docs/tutorials/explainability.html.md)
