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

# Custom Plots

> systematica.generic.custom_plots

## `plot_allocation`

```python theme={null}
plot_allocation(
    data: vectorbtpro.data.base.Data,
    signals: ~Signals,
    fig: vectorbtpro.utils.figure.FigureWidget = None,
)
```

Plot asset allocation based on trading signals.

**Parameters**:

| Name      | Type               | Default | Description                                    |
| --------- | ------------------ | ------- | ---------------------------------------------- |
| `data`    | `vbt.Data`         | `--`    | Data object containing asset prices.           |
| `signals` | `SignalsT`         | `--`    | Object containing trading signals.             |
| `fig`     | `vbt.FigureWidget` | `None`  | Existing figure to update. Defaults to `None`. |

**Returns**:

| Type               | Description                            |
| ------------------ | -------------------------------------- |
| `vbt.FigureWidget` | Figure containing the allocation plot. |

## `plot_signal_crossover`

```python theme={null}
plot_signal_crossover(
    model_output: pandas.core.series.Series,
    upper_crossed: pandas.core.series.Series,
    lower_crossed: pandas.core.series.Series,
    upper: float,
    lower: float,
) ‑> vectorbtpro.utils.figure.FigureWidget
```

Plot signal crossover points with upper and lower bounds.

**Parameters**:

| Name            | Type        | Default | Description                                  |
| --------------- | ----------- | ------- | -------------------------------------------- |
| `model_output`  | `pd.Series` | `--`    | Model output series.                         |
| `upper_crossed` | `pd.Series` | `--`    | Series indicating upper boundary crossovers. |
| `lower_crossed` | `pd.Series` | `--`    | Series indicating lower boundary crossovers. |
| `upper`         | `float`     | `--`    | Upper threshold value.                       |
| `lower`         | `float`     | `--`    | Lower threshold value.                       |

**Returns**:

| Type               | Description                           |
| ------------------ | ------------------------------------- |
| `vbt.FigureWidget` | Figure containing the crossover plot. |

## `plot_signal_vlines`

```python theme={null}
plot_signal_vlines(
    df: pandas.core.frame.DataFrame,
    symbol: str,
    signals: ~Signals,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
```

Plot long and short entry signals as vertical lines.

**Parameters**:

| Name          | Type           | Default | Description                                |
| ------------- | -------------- | ------- | ------------------------------------------ |
| `df`          | `pd.DataFrame` | `--`    | Dataframe containing price data.           |
| `symbol`      | `str`          | `--`    | Symbol for which to plot signals.          |
| `signals`     | `Signals`      | `--`    | Signal object containing entry points.     |
| `plot_kwargs` | `tp.Kwargs`    | `--`    | Additional keyword arguments for plotting. |

**Returns**:

| Type               | Description                                            |
| ------------------ | ------------------------------------------------------ |
| `vbt.FigureWidget` | A figure with entry signals plotted as vertical lines. |

## `plot_performance_matrix`

```python theme={null}
plot_performance_matrix(
    pf: Any,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
```

Create a performance matrix heatmap.

This function generates a heatmap of performance metrics for the given portfolio
by resampling returns data to a monthly frequency. The matrix displays monthly returns
by year, with an additional column for the total annual return.

**Parameters**:

| Name          | Type        | Default | Description                                                  |
| ------------- | ----------- | ------- | ------------------------------------------------------------ |
| `pf`          | `tp.Any`    | `--`    | The portfolio object containing return data.                 |
| `plot_kwargs` | `tp.Kwargs` | `--`    | Additional keyword arguments passed to the heatmap function. |

**Returns**:

| Type               | Description                                                        |
| ------------------ | ------------------------------------------------------------------ |
| `vbt.FigureWidget` | A Plotly `FigureWidget` containing the performance matrix heatmap. |

**Examples**:

```python theme={null}
>>> pf = ...  # Initialize your portfolio object
>>> fig = plot_performance_matrix(pf)
>>> fig.show()
```

## `plot_smas`

```python theme={null}
plot_smas(
    close: pandas.core.frame.DataFrame,
    timeperiods: list = None,
    length: int = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
```

Plot Simple Moving Averages (SMAs).

This function calculates and plots SMAs for the specified time periods.

**Parameters**:

| Name          | Type             | Default | Description                                                                  |
| ------------- | ---------------- | ------- | ---------------------------------------------------------------------------- |
| `close`       | `pd.DataFrame`   | `--`    | DataFrame containing closing prices.                                         |
| `timeperiods` | `list, optional` | `--`    | List of time periods for SMAs. Defaults to `[20, 50, 100, 200]`.             |
| `length`      | `int, optional`  | `--`    | Number of data points to include in the plot. Defaults to `None` (all data). |
| `plot_kwargs` | `tp.Kwargs`      | `--`    | Additional keyword arguments for customizing the plot.                       |

**Returns**:

| Type               | Description                                       |
| ------------------ | ------------------------------------------------- |
| `vbt.FigureWidget` | A Plotly `FigureWidget` containing the SMA plots. |

## `plot_bbands`

```python theme={null}
plot_bbands(
    close: pandas.core.frame.DataFrame,
    length: int = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
```

Plot Bollinger Bands.

This function calculates and plots Bollinger Bands for the given data.

**Parameters**:

| Name          | Type           | Default | Description                                                                  |
| ------------- | -------------- | ------- | ---------------------------------------------------------------------------- |
| `close`       | `pd.DataFrame` | `--`    | DataFrame containing closing prices.                                         |
| `length`      | `int`          | `None`  | Number of data points to include in the plot. Defaults to `None` (all data). |
| `plot_kwargs` | `tp.Kwargs`    | `--`    | Additional keyword arguments for customizing the plot.                       |

**Returns**:

| Type               | Description                                                  |
| ------------------ | ------------------------------------------------------------ |
| `vbt.FigureWidget` | A Plotly `FigureWidget` containing the Bollinger Bands plot. |

## `plot_slope_range`

```python theme={null}
plot_slope_range(
    close: pandas.core.frame.DataFrame,
    window: int = 50,
    length: int = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
```

Plot slope ranges for a moving average.

This function identifies and visualizes steep slopes in a moving average.

**Parameters**:

| Name          | Type           | Default | Description                                                                  |
| ------------- | -------------- | ------- | ---------------------------------------------------------------------------- |
| `close`       | `pd.DataFrame` | `--`    | DataFrame containing closing prices.                                         |
| `window`      | `int`          | `50`    | Window size for the moving average. Defaults to `50`.                        |
| `length`      | `int`          | `None`  | Number of data points to include in the plot. Defaults to `None` (all data). |
| `plot_kwargs` | `tp.Kwargs`    | `--`    | Additional keyword arguments for customizing the plot.                       |

**Returns**:

| Type               | Description                                              |
| ------------------ | -------------------------------------------------------- |
| `vbt.FigureWidget` | A Plotly `FigureWidget` containing the slope range plot. |

## `plot_pattern`

```python theme={null}
plot_pattern(
    close: pandas.core.frame.DataFrame,
    pattern: Union(annotations=(<class 'vectorbtpro.utils.params.Param'>, <class 'list'>), resolved=True) = None,
    window: int = 50,
    max_window: int = 120,
    min_similarity: float = 0.8,
    length: int = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
```

Plot pattern matches in price data.

This function identifies and visualizes occurrences of a specified pattern in the price data.

**Parameters**:

| Name             | Type           | Default | Description                                                                |
| ---------------- | -------------- | ------- | -------------------------------------------------------------------------- |
| `close`          | `pd.DataFrame` | `--`    | DataFrame containing closing prices.                                       |
| `pattern`        | `list`         | `--`    | or vbt.Param, default None Pattern to search for. Defaults None.           |
| `window`         | `int`          | `50`    | Minimum window size for pattern matching. Defaults to 50.                  |
| `max_window`     | `int`          | `120`   | Maximum window size for pattern matching. Defaults to 120.                 |
| `min_similarity` | `float`        | `0.8`   | Minimum similarity threshold for pattern matching. Defaults to 0.8.        |
| `length`         | `int`          | `None`  | Number of data points to include in the plot. Defaults to None (all data). |
| `plot_kwargs`    | `tp.Kwargs`    | `--`    | Additional keyword arguments for customizing the plot.                     |

**Returns**:

| Type               | Description                                                |
| ------------------ | ---------------------------------------------------------- |
| `vbt.FigureWidget` | A Plotly `FigureWidget` containing the pattern match plot. |

## `RegressionLine`

```python theme={null}
RegressionLine(
    data: pandas.core.frame.DataFrame | numpy.ndarray = None,
    x_labels: Sequence[Hashable] = None,
    trace_names: str | Sequence[str | None] | None = None,
    trace_kwargs: Dict[str, Any] | Sequence[Dict[str, Any] | None] | None = None,
    add_trace_kwargs: Dict[str, Any] | None = None,
    make_figure_kwargs: Dict[str, Any] | None = None,
    fig: plotly.basedatatypes.BaseFigure = None,
    use_gl: bool = None,
    **layout_kwargs,
)
```

Create a regression line plot.

Inherites from `vbt.Scatter`.

**Parameters**:

| Name                 | Type                    | Default | Description                                                                                                             |
| -------------------- | ----------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| `data`               | `pd.DataFrame`          | `--`    | Data in any format that can be converted to NumPy. Must be of shape (`x_labels`, `trace_names`).                        |
| `x_labels`           | `tp.Labels`             | `None`  | Labels for the x-axis. Must be of shape (`data.shape[0]`,).                                                             |
| `trace_names`        | `tp.TraceNames`         | `None`  | Trace names, corresponding to columns in pandas. Must be of shape (`data.shape[1]`,).                                   |
| `trace_kwargs`       | `tp.KwargsLikeSequence` | `None`  | Keyword arguments passed to `plotly.graph_objects.Scatter`. Can be specified per trace as a sequence of dicts.          |
| `add_trace_kwargs`   | `tp.KwargsLike`         | `None`  | Keyword arguments passed to `add_trace`.                                                                                |
| `make_figure_kwargs` | `tp.KwargsLike`         | `None`  | Keyword arguments passed to `vectorbtpro.utils.figure.make_figure`.                                                     |
| `fig`                | `tp.BaseFigure`         | `None`  | Figure to add traces to.                                                                                                |
| `use_gl`             | `bool`                  | `None`  | Whether to use WebGL for rendering. If `None`, it will be set to `True` if the data is large enough, otherwise `False`. |
| `layout_kwargs`      | `tp.Kwargs`             | `--`    | Keyword arguments for layout.                                                                                           |

### Ancestors

* `vectorbtpro.generic.plotting.Scatter`
* `vectorbtpro.generic.plotting.TraceType`
* `vectorbtpro.utils.config.Configured`
* `vectorbtpro.utils.config.HasSettings`
* `vectorbtpro.utils.caching.Cacheable`
* `vectorbtpro.utils.checks.Comparable`
* `vectorbtpro.utils.pickling.Pickleable`
* `vectorbtpro.utils.formatting.Prettified`
* `vectorbtpro.utils.chaining.Chainable`
* `vectorbtpro.generic.plotting.TraceUpdater`
* `vectorbtpro.utils.base.Base`

## `TargetPortfolio`

```python theme={null}
TargetPortfolio(
    data: pandas.core.series.Series = None,
    trace_names: str | Sequence[str | None] | None = None,
    trace_kwargs: Dict[str, Any] | Sequence[Dict[str, Any] | None] | None = None,
    add_trace_kwargs: Dict[str, Any] | None = None,
    make_figure_kwargs: Dict[str, Any] | None = None,
    fig: plotly.basedatatypes.BaseFigure = None,
    use_gl: bool = None,
    **layout_kwargs,
)
```

Create a target portfolio plot.

Inherites from `vbt.Scatter`.

**Parameters**:

| Name                 | Type                    | Default | Description                                                                                                             |
| -------------------- | ----------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| `data`               | `pd.Series`             | `None`  | Data in any format that can be converted to pandas Series. Must be of shape (`trace_names`,).                           |
| `trace_names`        | `tp.TraceNames`         | `None`  | Trace names, corresponding to columns in pandas. Must be of shape (`data.shape[0]`,).                                   |
| `trace_kwargs`       | `tp.KwargsLikeSequence` | `None`  | Keyword arguments passed to `plotly.graph_objects.Scatter`. Can be specified per trace as a sequence of dicts.          |
| `add_trace_kwargs`   | `tp.KwargsLike`         | `None`  | Keyword arguments passed to `add_trace`.                                                                                |
| `make_figure_kwargs` | `tp.KwargsLike`         | `None`  | Keyword arguments passed to `vectorbtpro.utils.figure.make_figure`.                                                     |
| `fig`                | `tp.BaseFigure`         | `None`  | Figure to add traces to.                                                                                                |
| `use_gl`             | `bool`                  | `None`  | Whether to use WebGL for rendering. If `None`, it will be set to `True` if the data is large enough, otherwise `False`. |
| `layout_kwargs`      | `tp.Kwargs`             | `--`    | Keyword arguments for layout.                                                                                           |

### Ancestors

* `vectorbtpro.generic.plotting.Scatter`
* `vectorbtpro.generic.plotting.TraceType`
* `vectorbtpro.utils.config.Configured`
* `vectorbtpro.utils.config.HasSettings`
* `vectorbtpro.utils.caching.Cacheable`
* `vectorbtpro.utils.checks.Comparable`
* `vectorbtpro.utils.pickling.Pickleable`
* `vectorbtpro.utils.formatting.Prettified`
* `vectorbtpro.utils.chaining.Chainable`
* `vectorbtpro.generic.plotting.TraceUpdater`
* `vectorbtpro.utils.base.Base`

## `Frontier`

```python theme={null}
Frontier(
    data: pandas.core.series.Series = None,
    trace_names: str | Sequence[str | None] | None = None,
    trace_kwargs: Dict[str, Any] | Sequence[Dict[str, Any] | None] | None = None,
    add_trace_kwargs: Dict[str, Any] | None = None,
    make_figure_kwargs: Dict[str, Any] | None = None,
    fig: plotly.basedatatypes.BaseFigure = None,
    use_gl: bool = None,
    **layout_kwargs,
)
```

Create a frontier plot.

Inherits from `vbt.Scatter`.

**Parameters**:

| Name                 | Type                    | Default | Description                                                                                                             |
| -------------------- | ----------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| `data`               | `pd.Series`             | `None`  | Data in any format that can be converted to pandas Series. Must be of shape (`trace_names`,).                           |
| `trace_names`        | `tp.TraceNames`         | `None`  | Trace names, corresponding to columns in pandas. Must be of shape (`data.shape[0]`,).                                   |
| `trace_kwargs`       | `tp.KwargsLikeSequence` | `None`  | Keyword arguments passed to `plotly.graph_objects.Scatter`. Can be specified per trace as a sequence of dicts.          |
| `add_trace_kwargs`   | `tp.KwargsLike`         | `None`  | Keyword arguments passed to `add_trace`.                                                                                |
| `make_figure_kwargs` | `tp.KwargsLike`         | `None`  | Keyword arguments passed to `vectorbtpro.utils.figure.make_figure`.                                                     |
| `fig`                | `tp.BaseFigure`         | `None`  | Figure to add traces to.                                                                                                |
| `use_gl`             | `bool`                  | `None`  | Whether to use WebGL for rendering. If `None`, it will be set to `True` if the data is large enough, otherwise `False`. |
| `layout_kwargs`      | `tp.Kwargs`             | `--`    | Keyword arguments for layout.                                                                                           |

### Ancestors

* `vectorbtpro.generic.plotting.Scatter`
* `vectorbtpro.generic.plotting.TraceType`
* `vectorbtpro.utils.config.Configured`
* `vectorbtpro.utils.config.HasSettings`
* `vectorbtpro.utils.caching.Cacheable`
* `vectorbtpro.utils.checks.Comparable`
* `vectorbtpro.utils.pickling.Pickleable`
* `vectorbtpro.utils.formatting.Prettified`
* `vectorbtpro.utils.chaining.Chainable`
* `vectorbtpro.generic.plotting.TraceUpdater`
* `vectorbtpro.utils.base.Base`

## `Pie`

```python theme={null}
Pie(
    data: pandas.core.frame.DataFrame | numpy.ndarray = None,
    rp_kwargs: Dict[str, Any] = None,
    trace_names: str | Sequence[str | None] | None = None,
    trace_kwargs: Dict[str, Any] | Sequence[Dict[str, Any] | None] | None = None,
    add_trace_kwargs: Dict[str, Any] | None = None,
    make_figure_kwargs: Dict[str, Any] | None = None,
    fig: plotly.basedatatypes.BaseFigure = None,
    **layout_kwargs,
)
```

Create a bar plot.

Inherits from `vbt.Configured` and `vbt.TraceUpdater`.

**Parameters**:

| Name                 | Type                    | Default | Description                                                                                                                                                                                                                                                 |
| -------------------- | ----------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data`               | `tp.Array`              | `None`  | Data in any format that can be converted to NumPy. Must be of shape (`trace_names`).                                                                                                                                                                        |
| `rp_kwargs`          | `tp.Kwargs`             | `None`  | Keyword arguments for `vectorbtpro.portfolio.utils.rp`. If `data` is not None, it will be used to compute the portfolio. If `data` is None, it will be used to compute the portfolio from `trace_names`.                                                    |
| `trace_names`        | `tp.TraceNames`         | `None`  | Trace names, corresponding to columns in pandas. Must be of shape (`data.shape[0]`,) if `data` is not None. If `data` is None, it must be of shape (`trace_names`,). If `trace_names` is a string, it will be used as the name for all traces.              |
| `trace_kwargs`       | `tp.KwargsLikeSequence` | `None`  | Keyword arguments passed to `plotly.graph_objects.Pie`. Can be specified per trace as a sequence of dicts. If `data` is not None, it will be used to compute the portfolio. If `data` is None, it will be used to compute the portfolio from `trace_names`. |
| `add_trace_kwargs`   | `tp.KwargsLike`         | `None`  | Keyword arguments passed to `add_trace`. If `data` is not None, it will be used to compute the portfolio. If `data` is None, it will be used to compute the portfolio from `trace_names`.                                                                   |
| `make_figure_kwargs` | `tp.KwargsLike`         | `None`  | Keyword arguments passed to `vectorbtpro.utils.figure.make_figure`. If `data` is not None, it will be used to compute the portfolio. If `data` is None, it will be used to compute the portfolio from `trace_names`.                                        |
| `fig`                | `tp.BaseFigure`         | `None`  | Figure to add traces to. If `None`, a new figure will be created. If `data` is not None, it will be used to compute the portfolio. If `data` is None, it will be used to compute the portfolio from `trace_names`.                                          |
| `layout_kwargs`      | `tp.Kwargs`             | `None`  | Keyword arguments for layout. If `data` is not None, it will be used to compute the portfolio. If `data` is None, it will be used to compute the portfolio from `trace_names`.                                                                              |

**Examples**:

```python theme={null}
>>> import numpy as np
>>> import systematica as sma
>>> pie = sma.Pie(
...     data=np.array([0.06, 0.02, 0.05, 0.09]),
...     trace_names=['SPY', 'TLT', 'XLF', 'XLE'],
... )
>>> pie.fig.show()
```

### Ancestors

* `vectorbtpro.utils.config.Configured`
* `vectorbtpro.utils.config.HasSettings`
* `vectorbtpro.utils.caching.Cacheable`
* `vectorbtpro.utils.checks.Comparable`
* `vectorbtpro.utils.pickling.Pickleable`
* `vectorbtpro.utils.formatting.Prettified`
* `vectorbtpro.utils.chaining.Chainable`
* `vectorbtpro.generic.plotting.TraceUpdater`
* `vectorbtpro.utils.base.Base`

### Static methods

#### `update_trace`

```python theme={null}
update_trace(
    trace: plotly.basedatatypes.BaseTraceType,
    data: numpy.ndarray,
)
```

Update the trace with new data.

**Parameters**:

| Name    | Type            | Default | Description                                                                           |
| ------- | --------------- | ------- | ------------------------------------------------------------------------------------- |
| `trace` | `BaseTraceType` | `--`    | Trace to update.                                                                      |
| `data`  | `tp.Array1d`    | `--`    | Data in any format that can be converted to NumPy. Must be of shape (`trace_names`,). |

### Methods

#### `update`

```python theme={null}
update(
    self,
    data: numpy.ndarray,
)
```

Update the plot with new data.

**Parameters**:

| Name   | Type           | Default | Description                                                                           |
| ------ | -------------- | ------- | ------------------------------------------------------------------------------------- |
| `data` | `tp.ArrayLike` | `--`    | Data in any format that can be converted to NumPy. Must be of shape (`trace_names`,). |
