(gallery_khat_facet_cols)=

# Pareto k diagnostics with column faceting

Faceted Pareto k plot using column layout to compare diagnostics across field dimensions



::::::{tab-set}
:class: full-width
:sync-group: backend

:::::{tab-item} Matplotlib
:sync: matplotlib

![Matplotlib version of plot_khat_facet_cols](_images/plot_khat_facet_cols.png)

:::::

:::::{tab-item} Bokeh
:sync: bokeh

```{bokeh-plot}
:source-position: none

from bokeh.plotting import show

import warnings

import numpy as np
from arviz_base import load_arviz_data
from arviz_base.labels import MapLabeller
from arviz_stats import loo

import arviz_plots as azp

azp.style.use("arviz-variat")

idata = load_arviz_data("rugby")
points_da = idata.log_likelihood.dataset[["home_points", "away_points"]].to_array(
dim="field"
)
idata.log_likelihood["points"] = points_da.assign_coords(field=["home", "away"])
idata.log_likelihood.coords["year"] = ("match", np.repeat([2014, 2015, 2016, 2017], 15))

warnings.filterwarnings("ignore", "Estimated shape parameter.*greater than 0.70")
warnings.filterwarnings("ignore", "Assuming dpi=100")
loo_result = loo(idata, var_name="points", pointwise=True)

pc = azp.plot_khat(
loo_result,
cols=["field"],
labeller=MapLabeller(coord_map={"field": {"home": "Home", "away": "Away"}}),
visuals={
"bin_text": True,
"hlines": {"color": "darkblue", "width": 2},
"title": True,
},
figure_kwargs={"figsize": (6, 4)},
backend="bokeh", # change to preferred backend
)



# for some reason the bokeh plot extension needs explicit use of show
show(pc.viz["figure"].item() if pc.viz["figure"].item() is not None else pc.viz["plot"].item())
```

Link to this page with the [bokeh tab selected](https://arviz-plots.readthedocs.io/en/latest//gallery/plot_khat_facet_cols.html?backend=bokeh#synchronised-tabs)
:::::

:::::{tab-item} Plotly
:sync: plotly

```{jupyter-execute}
:hide-code:

import warnings

import numpy as np
from arviz_base import load_arviz_data
from arviz_base.labels import MapLabeller
from arviz_stats import loo

import arviz_plots as azp

azp.style.use("arviz-variat")

idata = load_arviz_data("rugby")
points_da = idata.log_likelihood.dataset[["home_points", "away_points"]].to_array(
dim="field"
)
idata.log_likelihood["points"] = points_da.assign_coords(field=["home", "away"])
idata.log_likelihood.coords["year"] = ("match", np.repeat([2014, 2015, 2016, 2017], 15))

warnings.filterwarnings("ignore", "Estimated shape parameter.*greater than 0.70")
warnings.filterwarnings("ignore", "Assuming dpi=100")
loo_result = loo(idata, var_name="points", pointwise=True)

pc = azp.plot_khat(
loo_result,
cols=["field"],
labeller=MapLabeller(coord_map={"field": {"home": "Home", "away": "Away"}}),
visuals={
"bin_text": True,
"hlines": {"color": "darkblue", "width": 2},
"title": True,
},
figure_kwargs={"figsize": (6, 4)},
backend="plotly", # change to preferred backend
)

pc.show()
```

Link to this page with the [plotly tab selected](https://arviz-plots.readthedocs.io/en/latest//gallery/plot_khat_facet_cols.html?backend=plotly#synchronised-tabs)
:::::
::::::

```{literalinclude} _scripts/plot_khat_facet_cols.py
:emphasize-lines: 33
```



:::{seealso}
API Documentation: {func}`~arviz_plots.plot_khat`
:::



## Other examples with `plot_khat`

```{eval-rst}
.. minigallery:: plot_khat
```


:::{div} example-plot-download
{download}`Download Python Source Code: plot_khat_facet_cols.py<_scripts/plot_khat_facet_cols.py>`
:::
