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

> Time series visualizations

# Plotting

***

<a href="https://github.com/Nixtla/utilsforecast/blob/main/utilsforecast/plotting.py#L50" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### plot\_series

> ```text theme={null}
>  plot_series (df:Optional[~DFType]=None,
>               forecasts_df:Optional[~DFType]=None,
>               ids:Optional[List[str]]=None, plot_random:bool=True,
>               max_ids:int=8, models:Optional[List[str]]=None,
>               level:Optional[List[float]]=None,
>               max_insample_length:Optional[int]=None,
>               plot_anomalies:bool=False, engine:str='matplotlib',
>               palette:Optional[str]=None, id_col:str='unique_id',
>               time_col:str='ds', target_col:str='y', seed:int=0,
>               resampler_kwargs:Optional[Dict]=None, ax:Union[matplotlib.ax
>               es._axes.Axes,numpy.ndarray,ForwardRef('plotly.graph_objects
>               .Figure'),NoneType]=None)
> ```

*Plot forecasts and insample values.*

|                       | **Type**                        | **Default** | **Details**                                                                                                                                                                                                               |
| --------------------- | ------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| df                    | Optional                        | None        | DataFrame with columns \[`id_col`, `time_col`, `target_col`].                                                                                                                                                             |
| forecasts\_df         | Optional                        | None        | DataFrame with columns \[`id_col`, `time_col`] and models.                                                                                                                                                                |
| ids                   | Optional                        | None        | Time Series to plot.<br />If None, time series are selected randomly.                                                                                                                                                     |
| plot\_random          | bool                            | True        | Select time series to plot randomly.                                                                                                                                                                                      |
| max\_ids              | int                             | 8           | Maximum number of ids to plot.                                                                                                                                                                                            |
| models                | Optional                        | None        | Models to plot.                                                                                                                                                                                                           |
| level                 | Optional                        | None        | Prediction intervals to plot.                                                                                                                                                                                             |
| max\_insample\_length | Optional                        | None        | Maximum number of train/insample observations to be plotted.                                                                                                                                                              |
| plot\_anomalies       | bool                            | False       | Plot anomalies for each prediction interval.                                                                                                                                                                              |
| engine                | str                             | matplotlib  | Library used to plot. ‘plotly’, ‘plotly-resampler’ or ‘matplotlib’.                                                                                                                                                       |
| palette               | Optional                        | None        | Name of the matplotlib colormap to use for the plots. If None, uses the current style.                                                                                                                                    |
| id\_col               | str                             | unique\_id  | Column that identifies each serie.                                                                                                                                                                                        |
| time\_col             | str                             | ds          | Column that identifies each timestep, its values can be timestamps or integers.                                                                                                                                           |
| target\_col           | str                             | y           | Column that contains the target.                                                                                                                                                                                          |
| seed                  | int                             | 0           | Seed used for the random number generator. Only used if plot\_random is True.                                                                                                                                             |
| resampler\_kwargs     | Optional                        | None        | Keyword arguments to be passed to plotly-resampler constructor.<br />For further custumization (“show\_dash”) call the method,<br />store the plotting object and add the extra arguments to<br />its `show_dash` method. |
| ax                    | Union                           | None        | Object where plots will be added.                                                                                                                                                                                         |
| **Returns**           | **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')
```

<img src="https://mintcdn.com/nixtla-old-docs/kV2_MnGbqpQQ3Lwc/utilsforecast/imgs/plotting.png?fit=max&auto=format&n=kV2_MnGbqpQQ3Lwc&q=85&s=2c465e07815b04389b105a94f30c14a1" alt="" width="1883" height="361" data-path="utilsforecast/imgs/plotting.png" />
