We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add example to az.plot_hdi that shows how to plot hdi from InferenceData posterior or posterior predictive
## Tell us about it
The `az.plot_hdi` docs only show how to plot the hdi from synthetic data. What would be nice is if it also shows users how to plot the hdi from an `az.InferenceData` as thats the standard data representation most people will be working with.

![image](https://user-images.githubusercontent.com/7213793/103111300-5d0cdb00-4600-11eb-973e-3c710b4a63cc.png)

## Thoughts on implementation
Use one of the precomputed datasets that has a posterior predictive group and create a plot.

Here's an example of loading a dataset with posterior predictive group
https://arviz-devs.github.io/arviz/api/generated/arviz.plot_ppc.html

Here's an (unrelated) example where PyMC3 generates a trace and posterior predictive group and its used with `az.plot_hdi`

```
with pm.Model() as model_linear:
    β = pm.Normal('β', sd=10, shape=2)

    μ = pm.Deterministic('μ', pm.math.dot(babies[["Intercept", "Month"]], β))
    ϵ = pm.HalfNormal('ϵ', sd=10)

    length = pm.Normal('length', mu=μ, sd=ϵ, observed=babies.Length)

    linear_trace = pm.sample(2000, tune=4000)
    linear_ppc = pm.sample_posterior_predictive(inf_data_linear)
    inf_data_linear = az.from_pymc3(trace=linear_trace, posterior_predictive= linear_ppc)

fig, ax = plt.subplots()

ax.set_ylabel("Length")
ax.set_xlabel("Month");

μ_m = inf_data_linear.posterior["μ"].values.reshape(-1, babies.Length.shape[0]).mean(axis=0)

ax.plot(babies.Month, μ_m, c='C4')
az.plot_hdi(babies.Month, inf_data_linear.posterior_predictive["length"], hdi_prob=.94, ax=ax)

ax.plot(babies.Month, babies.Length, 'C0.', alpha=0.1)

plt.savefig('img/Baby_Length_Linear_Fit.png', dpi=300)

```
![image](https://user-images.githubusercontent.com/7213793/103111469-39e32b00-4602-11eb-8ab5-a9727900ed6e.png)
![image](https://user-images.githubusercontent.com/7213793/103111474-45ceed00-4602-11eb-8ec2-83c0fd7ca9bd.png)



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `arviz/plots/hdiplot.py`
Content:
```
1 """Plot highest density intervals for regression data."""
2 import warnings
3 
4 import numpy as np
5 from scipy.interpolate import griddata
6 from scipy.signal import savgol_filter
7 from xarray import Dataset
8 
9 from ..rcparams import rcParams
10 from ..stats import hdi
11 from .plot_utils import get_plotting_function
12 
13 
14 def plot_hdi(
15     x,
16     y=None,
17     hdi_prob=None,
18     hdi_data=None,
19     color="C1",
20     circular=False,
21     smooth=True,
22     smooth_kwargs=None,
23     figsize=None,
24     fill_kwargs=None,
25     plot_kwargs=None,
26     hdi_kwargs=None,
27     ax=None,
28     backend=None,
29     backend_kwargs=None,
30     show=None,
31 ):
32     r"""
33     Plot HDI intervals for regression data.
34 
35     Parameters
36     ----------
37     x : array-like
38         Values to plot.
39     y : array-like, optional
40         Values from which to compute the HDI. Assumed shape ``(chain, draw, \*shape)``.
41         Only optional if hdi_data is present.
42     hdi_data : array_like, optional
43         Precomputed HDI values to use. Assumed shape is ``(*x.shape, 2)``.
44     hdi_prob : float, optional
45         Probability for the highest density interval. Defaults to ``stats.hdi_prob`` rcParam.
46     color : str, optional
47         Color used for the limits of the HDI and fill. Should be a valid matplotlib color.
48     circular : bool, optional
49         Whether to compute the HDI taking into account `x` is a circular variable
50         (in the range [-np.pi, np.pi]) or not. Defaults to False (i.e non-circular variables).
51     smooth : boolean, optional
52         If True the result will be smoothed by first computing a linear interpolation of the data
53         over a regular grid and then applying the Savitzky-Golay filter to the interpolated data.
54         Defaults to True.
55     smooth_kwargs : dict, optional
56         Additional keywords modifying the Savitzky-Golay filter. See
57         :func:`scipy:scipy.signal.savgol_filter` for details.
58     figsize : tuple
59         Figure size. If None it will be defined automatically.
60     fill_kwargs : dict, optional
61         Keywords passed to :meth:`mpl:matplotlib.axes.Axes.fill_between`
62         (use fill_kwargs={'alpha': 0} to disable fill) or to
63         :meth:`bokeh:bokeh.plotting.figure.Figure.patch`.
64     plot_kwargs : dict, optional
65         HDI limits keyword arguments, passed to :meth:`mpl:matplotlib.axes.Axes.plot` or
66         :meth:`bokeh:bokeh.plotting.figure.Figure.patch`.
67     hdi_kwargs : dict, optional
68         Keyword arguments passed to :func:`~arviz.hdi`. Ignored if ``hdi_data`` is present.
69     ax : axes, optional
70         Matplotlib axes or bokeh figures.
71     backend : {"matplotlib","bokeh"}, optional
72         Select plotting backend.
73     backend_kwargs : bool, optional
74         These are kwargs specific to the backend being used. Passed to ::``
75     show : bool, optional
76         Call backend show function.
77 
78     Returns
79     -------
80     axes : matplotlib axes or bokeh figures
81 
82     See Also
83     --------
84     hdi : Calculate highest density interval (HDI) of array for given probability.
85 
86     Examples
87     --------
88     Plot HDI interval of simulated regression data using `y` argument:
89 
90     .. plot::
91         :context: close-figs
92 
93         >>> import numpy as np
94         >>> import arviz as az
95         >>> x_data = np.random.normal(0, 1, 100)
96         >>> y_data = np.random.normal(2 + x_data * 0.5, 0.5, (2, 50, 100))
97         >>> az.plot_hdi(x_data, y_data)
98 
99     ``plot_hdi`` can also be given precalculated values with the argument ``hdi_data``. This example
100     shows how to use :func:`~arviz.hdi` to precalculate the values and pass these values to
101     ``plot_hdi``. Similarly to an example in ``hdi`` we are using the ``input_core_dims``
102     argument of :func:`~arviz.wrap_xarray_ufunc` to manually define the dimensions over which
103     to calculate the HDI.
104 
105     .. plot::
106         :context: close-figs
107 
108         >>> hdi_data = az.hdi(y_data, input_core_dims=[["draw"]])
109         >>> ax = az.plot_hdi(x_data, hdi_data=hdi_data[0], color="r", fill_kwargs={"alpha": .2})
110         >>> az.plot_hdi(x_data, hdi_data=hdi_data[1], color="k", ax=ax, fill_kwargs={"alpha": .2})
111 
112     """
113     if hdi_kwargs is None:
114         hdi_kwargs = {}
115 
116     x = np.asarray(x)
117     x_shape = x.shape
118 
119     if y is None and hdi_data is None:
120         raise ValueError("One of {y, hdi_data} is required")
121     if hdi_data is not None and y is not None:
122         warnings.warn("Both y and hdi_data arguments present, ignoring y")
123     elif hdi_data is not None:
124         hdi_prob = (
125             hdi_data.hdi.attrs.get("hdi_prob", np.nan) if hasattr(hdi_data, "hdi") else np.nan
126         )
127         if isinstance(hdi_data, Dataset):
128             data_vars = list(hdi_data.data_vars)
129             if len(data_vars) != 1:
130                 raise ValueError(
131                     "Found several variables in hdi_data. Only single variable Datasets are "
132                     "supported."
133                 )
134             hdi_data = hdi_data[data_vars[0]]
135     else:
136         y = np.asarray(y)
137         if hdi_prob is None:
138             hdi_prob = rcParams["stats.hdi_prob"]
139         else:
140             if not 1 >= hdi_prob > 0:
141                 raise ValueError("The value of hdi_prob should be in the interval (0, 1]")
142         hdi_data = hdi(y, hdi_prob=hdi_prob, circular=circular, multimodal=False, **hdi_kwargs)
143 
144     hdi_shape = hdi_data.shape
145     if hdi_shape[:-1] != x_shape:
146         msg = (
147             "Dimension mismatch for x: {} and hdi: {}. Check the dimensions of y and"
148             "hdi_kwargs to make sure they are compatible"
149         )
150         raise TypeError(msg.format(x_shape, hdi_shape))
151 
152     if smooth:
153         if smooth_kwargs is None:
154             smooth_kwargs = {}
155         smooth_kwargs.setdefault("window_length", 55)
156         smooth_kwargs.setdefault("polyorder", 2)
157         x_data = np.linspace(x.min(), x.max(), 200)
158         x_data[0] = (x_data[0] + x_data[1]) / 2
159         hdi_interp = griddata(x, hdi_data, x_data)
160         y_data = savgol_filter(hdi_interp, axis=0, **smooth_kwargs)
161     else:
162         idx = np.argsort(x)
163         x_data = x[idx]
164         y_data = hdi_data[idx]
165 
166     hdiplot_kwargs = dict(
167         ax=ax,
168         x_data=x_data,
169         y_data=y_data,
170         color=color,
171         figsize=figsize,
172         plot_kwargs=plot_kwargs,
173         fill_kwargs=fill_kwargs,
174         backend_kwargs=backend_kwargs,
175         show=show,
176     )
177 
178     if backend is None:
179         backend = rcParams["plot.backend"]
180     backend = backend.lower()
181 
182     plot = get_plotting_function("plot_hdi", "hdiplot", backend)
183     ax = plot(**hdiplot_kwargs)
184     return ax
185
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/arviz/plots/hdiplot.py b/arviz/plots/hdiplot.py
--- a/arviz/plots/hdiplot.py
+++ b/arviz/plots/hdiplot.py
@@ -109,6 +109,19 @@
         >>> ax = az.plot_hdi(x_data, hdi_data=hdi_data[0], color="r", fill_kwargs={"alpha": .2})
         >>> az.plot_hdi(x_data, hdi_data=hdi_data[1], color="k", ax=ax, fill_kwargs={"alpha": .2})
 
+    ``plot_hdi`` can also be used with Inference Data objects. Here we use the posterior predictive
+    to plot the HDI interval.
+
+    .. plot::
+        :context: close-figs
+
+        >>> X = np.random.normal(0,1,100)
+        >>> Y = np.random.normal(2 + X * 0.5, 0.5, (10,100))
+        >>> idata = az.from_dict(posterior={"y": Y}, constant_data={"x":X})
+        >>> x_data = idata.constant_data.x
+        >>> y_data = idata.posterior.y
+        >>> az.plot_hdi(x_data, y_data)
+
     """
     if hdi_kwargs is None:
         hdi_kwargs = {}

{"golden_diff": "diff --git a/arviz/plots/hdiplot.py b/arviz/plots/hdiplot.py\n--- a/arviz/plots/hdiplot.py\n+++ b/arviz/plots/hdiplot.py\n@@ -109,6 +109,19 @@\n         >>> ax = az.plot_hdi(x_data, hdi_data=hdi_data[0], color=\"r\", fill_kwargs={\"alpha\": .2})\n         >>> az.plot_hdi(x_data, hdi_data=hdi_data[1], color=\"k\", ax=ax, fill_kwargs={\"alpha\": .2})\n \n+    ``plot_hdi`` can also be used with Inference Data objects. Here we use the posterior predictive\n+    to plot the HDI interval.\n+\n+    .. plot::\n+        :context: close-figs\n+\n+        >>> X = np.random.normal(0,1,100)\n+        >>> Y = np.random.normal(2 + X * 0.5, 0.5, (10,100))\n+        >>> idata = az.from_dict(posterior={\"y\": Y}, constant_data={\"x\":X})\n+        >>> x_data = idata.constant_data.x\n+        >>> y_data = idata.posterior.y\n+        >>> az.plot_hdi(x_data, y_data)\n+\n     \"\"\"\n     if hdi_kwargs is None:\n         hdi_kwargs = {}\n", "issue": "Add example to az.plot_hdi that shows how to plot hdi from InferenceData posterior or posterior predictive\n## Tell us about it\r\nThe `az.plot_hdi` docs only show how to plot the hdi from synthetic data. What would be nice is if it also shows users how to plot the hdi from an `az.InferenceData` as thats the standard data representation most people will be working with.\r\n\r\n![image](https://user-images.githubusercontent.com/7213793/103111300-5d0cdb00-4600-11eb-973e-3c710b4a63cc.png)\r\n\r\n## Thoughts on implementation\r\nUse one of the precomputed datasets that has a posterior predictive group and create a plot.\r\n\r\nHere's an example of loading a dataset with posterior predictive group\r\nhttps://arviz-devs.github.io/arviz/api/generated/arviz.plot_ppc.html\r\n\r\nHere's an (unrelated) example where PyMC3 generates a trace and posterior predictive group and its used with `az.plot_hdi`\r\n\r\n```\r\nwith pm.Model() as model_linear:\r\n    \u03b2 = pm.Normal('\u03b2', sd=10, shape=2)\r\n\r\n    \u03bc = pm.Deterministic('\u03bc', pm.math.dot(babies[[\"Intercept\", \"Month\"]], \u03b2))\r\n    \u03f5 = pm.HalfNormal('\u03f5', sd=10)\r\n\r\n    length = pm.Normal('length', mu=\u03bc, sd=\u03f5, observed=babies.Length)\r\n\r\n    linear_trace = pm.sample(2000, tune=4000)\r\n    linear_ppc = pm.sample_posterior_predictive(inf_data_linear)\r\n    inf_data_linear = az.from_pymc3(trace=linear_trace, posterior_predictive= linear_ppc)\r\n\r\nfig, ax = plt.subplots()\r\n\r\nax.set_ylabel(\"Length\")\r\nax.set_xlabel(\"Month\");\r\n\r\n\u03bc_m = inf_data_linear.posterior[\"\u03bc\"].values.reshape(-1, babies.Length.shape[0]).mean(axis=0)\r\n\r\nax.plot(babies.Month, \u03bc_m, c='C4')\r\naz.plot_hdi(babies.Month, inf_data_linear.posterior_predictive[\"length\"], hdi_prob=.94, ax=ax)\r\n\r\nax.plot(babies.Month, babies.Length, 'C0.', alpha=0.1)\r\n\r\nplt.savefig('img/Baby_Length_Linear_Fit.png', dpi=300)\r\n\r\n```\r\n![image](https://user-images.githubusercontent.com/7213793/103111469-39e32b00-4602-11eb-8ab5-a9727900ed6e.png)\r\n![image](https://user-images.githubusercontent.com/7213793/103111474-45ceed00-4602-11eb-8ec2-83c0fd7ca9bd.png)\r\n\r\n\n", "before_files": [{"content": "\"\"\"Plot highest density intervals for regression data.\"\"\"\nimport warnings\n\nimport numpy as np\nfrom scipy.interpolate import griddata\nfrom scipy.signal import savgol_filter\nfrom xarray import Dataset\n\nfrom ..rcparams import rcParams\nfrom ..stats import hdi\nfrom .plot_utils import get_plotting_function\n\n\ndef plot_hdi(\n    x,\n    y=None,\n    hdi_prob=None,\n    hdi_data=None,\n    color=\"C1\",\n    circular=False,\n    smooth=True,\n    smooth_kwargs=None,\n    figsize=None,\n    fill_kwargs=None,\n    plot_kwargs=None,\n    hdi_kwargs=None,\n    ax=None,\n    backend=None,\n    backend_kwargs=None,\n    show=None,\n):\n    r\"\"\"\n    Plot HDI intervals for regression data.\n\n    Parameters\n    ----------\n    x : array-like\n        Values to plot.\n    y : array-like, optional\n        Values from which to compute the HDI. Assumed shape ``(chain, draw, \\*shape)``.\n        Only optional if hdi_data is present.\n    hdi_data : array_like, optional\n        Precomputed HDI values to use. Assumed shape is ``(*x.shape, 2)``.\n    hdi_prob : float, optional\n        Probability for the highest density interval. Defaults to ``stats.hdi_prob`` rcParam.\n    color : str, optional\n        Color used for the limits of the HDI and fill. Should be a valid matplotlib color.\n    circular : bool, optional\n        Whether to compute the HDI taking into account `x` is a circular variable\n        (in the range [-np.pi, np.pi]) or not. Defaults to False (i.e non-circular variables).\n    smooth : boolean, optional\n        If True the result will be smoothed by first computing a linear interpolation of the data\n        over a regular grid and then applying the Savitzky-Golay filter to the interpolated data.\n        Defaults to True.\n    smooth_kwargs : dict, optional\n        Additional keywords modifying the Savitzky-Golay filter. See\n        :func:`scipy:scipy.signal.savgol_filter` for details.\n    figsize : tuple\n        Figure size. If None it will be defined automatically.\n    fill_kwargs : dict, optional\n        Keywords passed to :meth:`mpl:matplotlib.axes.Axes.fill_between`\n        (use fill_kwargs={'alpha': 0} to disable fill) or to\n        :meth:`bokeh:bokeh.plotting.figure.Figure.patch`.\n    plot_kwargs : dict, optional\n        HDI limits keyword arguments, passed to :meth:`mpl:matplotlib.axes.Axes.plot` or\n        :meth:`bokeh:bokeh.plotting.figure.Figure.patch`.\n    hdi_kwargs : dict, optional\n        Keyword arguments passed to :func:`~arviz.hdi`. Ignored if ``hdi_data`` is present.\n    ax : axes, optional\n        Matplotlib axes or bokeh figures.\n    backend : {\"matplotlib\",\"bokeh\"}, optional\n        Select plotting backend.\n    backend_kwargs : bool, optional\n        These are kwargs specific to the backend being used. Passed to ::``\n    show : bool, optional\n        Call backend show function.\n\n    Returns\n    -------\n    axes : matplotlib axes or bokeh figures\n\n    See Also\n    --------\n    hdi : Calculate highest density interval (HDI) of array for given probability.\n\n    Examples\n    --------\n    Plot HDI interval of simulated regression data using `y` argument:\n\n    .. plot::\n        :context: close-figs\n\n        >>> import numpy as np\n        >>> import arviz as az\n        >>> x_data = np.random.normal(0, 1, 100)\n        >>> y_data = np.random.normal(2 + x_data * 0.5, 0.5, (2, 50, 100))\n        >>> az.plot_hdi(x_data, y_data)\n\n    ``plot_hdi`` can also be given precalculated values with the argument ``hdi_data``. This example\n    shows how to use :func:`~arviz.hdi` to precalculate the values and pass these values to\n    ``plot_hdi``. Similarly to an example in ``hdi`` we are using the ``input_core_dims``\n    argument of :func:`~arviz.wrap_xarray_ufunc` to manually define the dimensions over which\n    to calculate the HDI.\n\n    .. plot::\n        :context: close-figs\n\n        >>> hdi_data = az.hdi(y_data, input_core_dims=[[\"draw\"]])\n        >>> ax = az.plot_hdi(x_data, hdi_data=hdi_data[0], color=\"r\", fill_kwargs={\"alpha\": .2})\n        >>> az.plot_hdi(x_data, hdi_data=hdi_data[1], color=\"k\", ax=ax, fill_kwargs={\"alpha\": .2})\n\n    \"\"\"\n    if hdi_kwargs is None:\n        hdi_kwargs = {}\n\n    x = np.asarray(x)\n    x_shape = x.shape\n\n    if y is None and hdi_data is None:\n        raise ValueError(\"One of {y, hdi_data} is required\")\n    if hdi_data is not None and y is not None:\n        warnings.warn(\"Both y and hdi_data arguments present, ignoring y\")\n    elif hdi_data is not None:\n        hdi_prob = (\n            hdi_data.hdi.attrs.get(\"hdi_prob\", np.nan) if hasattr(hdi_data, \"hdi\") else np.nan\n        )\n        if isinstance(hdi_data, Dataset):\n            data_vars = list(hdi_data.data_vars)\n            if len(data_vars) != 1:\n                raise ValueError(\n                    \"Found several variables in hdi_data. Only single variable Datasets are \"\n                    \"supported.\"\n                )\n            hdi_data = hdi_data[data_vars[0]]\n    else:\n        y = np.asarray(y)\n        if hdi_prob is None:\n            hdi_prob = rcParams[\"stats.hdi_prob\"]\n        else:\n            if not 1 >= hdi_prob > 0:\n                raise ValueError(\"The value of hdi_prob should be in the interval (0, 1]\")\n        hdi_data = hdi(y, hdi_prob=hdi_prob, circular=circular, multimodal=False, **hdi_kwargs)\n\n    hdi_shape = hdi_data.shape\n    if hdi_shape[:-1] != x_shape:\n        msg = (\n            \"Dimension mismatch for x: {} and hdi: {}. Check the dimensions of y and\"\n            \"hdi_kwargs to make sure they are compatible\"\n        )\n        raise TypeError(msg.format(x_shape, hdi_shape))\n\n    if smooth:\n        if smooth_kwargs is None:\n            smooth_kwargs = {}\n        smooth_kwargs.setdefault(\"window_length\", 55)\n        smooth_kwargs.setdefault(\"polyorder\", 2)\n        x_data = np.linspace(x.min(), x.max(), 200)\n        x_data[0] = (x_data[0] + x_data[1]) / 2\n        hdi_interp = griddata(x, hdi_data, x_data)\n        y_data = savgol_filter(hdi_interp, axis=0, **smooth_kwargs)\n    else:\n        idx = np.argsort(x)\n        x_data = x[idx]\n        y_data = hdi_data[idx]\n\n    hdiplot_kwargs = dict(\n        ax=ax,\n        x_data=x_data,\n        y_data=y_data,\n        color=color,\n        figsize=figsize,\n        plot_kwargs=plot_kwargs,\n        fill_kwargs=fill_kwargs,\n        backend_kwargs=backend_kwargs,\n        show=show,\n    )\n\n    if backend is None:\n        backend = rcParams[\"plot.backend\"]\n    backend = backend.lower()\n\n    plot = get_plotting_function(\"plot_hdi\", \"hdiplot\", backend)\n    ax = plot(**hdiplot_kwargs)\n    return ax\n", "path": "arviz/plots/hdiplot.py"}], "after_files": [{"content": "\"\"\"Plot highest density intervals for regression data.\"\"\"\nimport warnings\n\nimport numpy as np\nfrom scipy.interpolate import griddata\nfrom scipy.signal import savgol_filter\nfrom xarray import Dataset\n\nfrom ..rcparams import rcParams\nfrom ..stats import hdi\nfrom .plot_utils import get_plotting_function\n\n\ndef plot_hdi(\n    x,\n    y=None,\n    hdi_prob=None,\n    hdi_data=None,\n    color=\"C1\",\n    circular=False,\n    smooth=True,\n    smooth_kwargs=None,\n    figsize=None,\n    fill_kwargs=None,\n    plot_kwargs=None,\n    hdi_kwargs=None,\n    ax=None,\n    backend=None,\n    backend_kwargs=None,\n    show=None,\n):\n    r\"\"\"\n    Plot HDI intervals for regression data.\n\n    Parameters\n    ----------\n    x : array-like\n        Values to plot.\n    y : array-like, optional\n        Values from which to compute the HDI. Assumed shape ``(chain, draw, \\*shape)``.\n        Only optional if hdi_data is present.\n    hdi_data : array_like, optional\n        Precomputed HDI values to use. Assumed shape is ``(*x.shape, 2)``.\n    hdi_prob : float, optional\n        Probability for the highest density interval. Defaults to ``stats.hdi_prob`` rcParam.\n    color : str, optional\n        Color used for the limits of the HDI and fill. Should be a valid matplotlib color.\n    circular : bool, optional\n        Whether to compute the HDI taking into account `x` is a circular variable\n        (in the range [-np.pi, np.pi]) or not. Defaults to False (i.e non-circular variables).\n    smooth : boolean, optional\n        If True the result will be smoothed by first computing a linear interpolation of the data\n        over a regular grid and then applying the Savitzky-Golay filter to the interpolated data.\n        Defaults to True.\n    smooth_kwargs : dict, optional\n        Additional keywords modifying the Savitzky-Golay filter. See\n        :func:`scipy:scipy.signal.savgol_filter` for details.\n    figsize : tuple\n        Figure size. If None it will be defined automatically.\n    fill_kwargs : dict, optional\n        Keywords passed to :meth:`mpl:matplotlib.axes.Axes.fill_between`\n        (use fill_kwargs={'alpha': 0} to disable fill) or to\n        :meth:`bokeh:bokeh.plotting.figure.Figure.patch`.\n    plot_kwargs : dict, optional\n        HDI limits keyword arguments, passed to :meth:`mpl:matplotlib.axes.Axes.plot` or\n        :meth:`bokeh:bokeh.plotting.figure.Figure.patch`.\n    hdi_kwargs : dict, optional\n        Keyword arguments passed to :func:`~arviz.hdi`. Ignored if ``hdi_data`` is present.\n    ax : axes, optional\n        Matplotlib axes or bokeh figures.\n    backend : {\"matplotlib\",\"bokeh\"}, optional\n        Select plotting backend.\n    backend_kwargs : bool, optional\n        These are kwargs specific to the backend being used. Passed to ::``\n    show : bool, optional\n        Call backend show function.\n\n    Returns\n    -------\n    axes : matplotlib axes or bokeh figures\n\n    See Also\n    --------\n    hdi : Calculate highest density interval (HDI) of array for given probability.\n\n    Examples\n    --------\n    Plot HDI interval of simulated regression data using `y` argument:\n\n    .. plot::\n        :context: close-figs\n\n        >>> import numpy as np\n        >>> import arviz as az\n        >>> x_data = np.random.normal(0, 1, 100)\n        >>> y_data = np.random.normal(2 + x_data * 0.5, 0.5, (2, 50, 100))\n        >>> az.plot_hdi(x_data, y_data)\n\n    ``plot_hdi`` can also be given precalculated values with the argument ``hdi_data``. This example\n    shows how to use :func:`~arviz.hdi` to precalculate the values and pass these values to\n    ``plot_hdi``. Similarly to an example in ``hdi`` we are using the ``input_core_dims``\n    argument of :func:`~arviz.wrap_xarray_ufunc` to manually define the dimensions over which\n    to calculate the HDI.\n\n    .. plot::\n        :context: close-figs\n\n        >>> hdi_data = az.hdi(y_data, input_core_dims=[[\"draw\"]])\n        >>> ax = az.plot_hdi(x_data, hdi_data=hdi_data[0], color=\"r\", fill_kwargs={\"alpha\": .2})\n        >>> az.plot_hdi(x_data, hdi_data=hdi_data[1], color=\"k\", ax=ax, fill_kwargs={\"alpha\": .2})\n\n    ``plot_hdi`` can also be used with Inference Data objects. Here we use the posterior predictive\n    to plot the HDI interval.\n\n    .. plot::\n        :context: close-figs\n\n        >>> X = np.random.normal(0,1,100)\n        >>> Y = np.random.normal(2 + X * 0.5, 0.5, (10,100))\n        >>> idata = az.from_dict(posterior={\"y\": Y}, constant_data={\"x\":X})\n        >>> x_data = idata.constant_data.x\n        >>> y_data = idata.posterior.y\n        >>> az.plot_hdi(x_data, y_data)\n\n    \"\"\"\n    if hdi_kwargs is None:\n        hdi_kwargs = {}\n\n    x = np.asarray(x)\n    x_shape = x.shape\n\n    if y is None and hdi_data is None:\n        raise ValueError(\"One of {y, hdi_data} is required\")\n    if hdi_data is not None and y is not None:\n        warnings.warn(\"Both y and hdi_data arguments present, ignoring y\")\n    elif hdi_data is not None:\n        hdi_prob = (\n            hdi_data.hdi.attrs.get(\"hdi_prob\", np.nan) if hasattr(hdi_data, \"hdi\") else np.nan\n        )\n        if isinstance(hdi_data, Dataset):\n            data_vars = list(hdi_data.data_vars)\n            if len(data_vars) != 1:\n                raise ValueError(\n                    \"Found several variables in hdi_data. Only single variable Datasets are \"\n                    \"supported.\"\n                )\n            hdi_data = hdi_data[data_vars[0]]\n    else:\n        y = np.asarray(y)\n        if hdi_prob is None:\n            hdi_prob = rcParams[\"stats.hdi_prob\"]\n        else:\n            if not 1 >= hdi_prob > 0:\n                raise ValueError(\"The value of hdi_prob should be in the interval (0, 1]\")\n        hdi_data = hdi(y, hdi_prob=hdi_prob, circular=circular, multimodal=False, **hdi_kwargs)\n\n    hdi_shape = hdi_data.shape\n    if hdi_shape[:-1] != x_shape:\n        msg = (\n            \"Dimension mismatch for x: {} and hdi: {}. Check the dimensions of y and\"\n            \"hdi_kwargs to make sure they are compatible\"\n        )\n        raise TypeError(msg.format(x_shape, hdi_shape))\n\n    if smooth:\n        if smooth_kwargs is None:\n            smooth_kwargs = {}\n        smooth_kwargs.setdefault(\"window_length\", 55)\n        smooth_kwargs.setdefault(\"polyorder\", 2)\n        x_data = np.linspace(x.min(), x.max(), 200)\n        x_data[0] = (x_data[0] + x_data[1]) / 2\n        hdi_interp = griddata(x, hdi_data, x_data)\n        y_data = savgol_filter(hdi_interp, axis=0, **smooth_kwargs)\n    else:\n        idx = np.argsort(x)\n        x_data = x[idx]\n        y_data = hdi_data[idx]\n\n    hdiplot_kwargs = dict(\n        ax=ax,\n        x_data=x_data,\n        y_data=y_data,\n        color=color,\n        figsize=figsize,\n        plot_kwargs=plot_kwargs,\n        fill_kwargs=fill_kwargs,\n        backend_kwargs=backend_kwargs,\n        show=show,\n    )\n\n    if backend is None:\n        backend = rcParams[\"plot.backend\"]\n    backend = backend.lower()\n\n    plot = get_plotting_function(\"plot_hdi\", \"hdiplot\", backend)\n    ax = plot(**hdiplot_kwargs)\n    return ax\n", "path": "arviz/plots/hdiplot.py"}]}