# Plots

> One chart for every result, from forecasts to calibration.

`yhatlabs.plots` draws every result with matplotlib (`pip install "yhatlabs[plot]"`). Each function returns the Figure, so
`.savefig(...)` or further styling works as usual.

```python
from yhatlabs import plots
```

| Function | Draws | Also as |
|---|---|---|
| `plots.forecast(fc, history=df)` | the median and every interval as nested bands, after the history | `fc.plot(...)` |
| `plots.backtest(ev)` | actuals across the windows, each window's forecast, the cutoffs | `ev.plot()` |
| `plots.calibration(ev)` | forecast quantiles: nominal level against the share of actuals below it | `ev.plot_calibration()` |
| `plots.anomalies(flags)` | the series, its expected range and the flagged points | |
| `plots.scenarios(sc, history=df)` | one line and band per scenario | |
| `plots.reliability(ev)` | classification: predicted probability against observed frequency | `ev.plot()` on a table evaluation |
| `plots.predicted_vs_actual(res, y)` | regression: predictions against true values, with interval bars | `ev.plot()` on a regression evaluation |
| `plots.importance(imp)` | permutation importance bars with their spread | |
| `plots.effect(eff)` | an effect curve: the average prediction and the spread across rows | |

The forecast plots take `ids=[...]` or `max_series=` (default 4) to choose which series to draw, and `ax=` to draw into
your own axes.

## Forecasts

![Forecast with nested 50% and 80% bands after the history](https://yhatlabs.com/models/docs/img/ts_plot_forecast-forecast.png)

**`fc.plot(history=df)`**: the history in grey, then the median forecast with its 50% and 80% intervals as nested bands; the darker band is where the actual is more likely to land.

![Backtest windows with cutoffs](https://yhatlabs.com/models/docs/img/ts_plot_backtest-backtest.png)

**`ev.plot()`**: a backtest. The dark line is what happened; each blue block is a forecast made at the dotted cutoff, without seeing anything after it. Actuals outside the bands are misses.

![Anomalies: expected range and flagged points](https://yhatlabs.com/models/docs/img/ts_plot_anomalies-anomalies.png)

**`plots.anomalies(flags)`**: the shaded band is the range the model expected each point in (q10 to q90 of a forecast made just before it); red points are the readings flagged as anomalies.

## Tables

![Reliability diagram](https://yhatlabs.com/models/docs/img/tab_evaluate-reliability.png)

**`plots.reliability(ev)`**: are the probabilities honest? Each point groups the rows given a similar probability and plots how often the event happened. On the dashed diagonal, a 70% means 70%.

![Predicted against actual with intervals](https://yhatlabs.com/models/docs/img/tab_evaluate_regression-predicted_vs_actual.png)

**`plots.predicted_vs_actual(res, y)`**: each dot is a row, predicted against true; the bars are its 90% interval. Close to the dashed diagonal is accurate, and a bar crossing it means the interval held the true value.

![Importance bars](https://yhatlabs.com/models/docs/img/tab_effect-importance.png)

**`plots.importance(imp)`**: how much the score drops when a column's values are shuffled. Longer bars are columns the model relies on more; the black line is the spread over repeats.

![Effect curve](https://yhatlabs.com/models/docs/img/tab_effect-effect.png)

**`plots.effect(eff)`**: how the prediction moves as one column changes, everything else as in real rows. The line is the average; the band shows how much that differs between rows.

The code for each is on the page of the feature: [Forecasting](https://yhatlabs.com/models/docs/time-series/forecasting#plot),
[Backtesting](https://yhatlabs.com/models/docs/time-series/backtesting#plot-the-backtest), [Anomalies](https://yhatlabs.com/models/docs/time-series/anomalies-and-gaps),
[Evaluating on your data](https://yhatlabs.com/models/docs/tabular/evaluating), [Effects](https://yhatlabs.com/models/docs/tabular/intervals-and-importance#effects).
