We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
HPD plot shows values over each other
Hey All,

I am trying to figure out how to change the plot_posterior function to show the actual values.  In one of my plots, where it is small, I get numbers writing over each other.  Any help/advice?

![image](https://user-images.githubusercontent.com/605973/85463990-c71ec780-b56c-11ea-95f6-3706e6ef72a1.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/backends/matplotlib/posteriorplot.py`
Content:
```
1 """Matplotlib Plot posterior densities."""
2 from typing import Optional
3 from numbers import Number
4 import matplotlib.pyplot as plt
5 import numpy as np
6 
7 from . import backend_show
8 from ....stats import hdi
9 from ...kdeplot import plot_kde
10 from ...plot_utils import (
11     make_label,
12     _create_axes_grid,
13     format_sig_figs,
14     round_num,
15     calculate_point_estimate,
16 )
17 from ....numeric_utils import get_bins
18 
19 
20 def plot_posterior(
21     ax,
22     length_plotters,
23     rows,
24     cols,
25     figsize,
26     plotters,
27     bw,
28     bins,
29     kind,
30     point_estimate,
31     round_to,
32     hdi_prob,
33     multimodal,
34     ref_val,
35     rope,
36     ax_labelsize,
37     xt_labelsize,
38     kwargs,
39     titlesize,
40     backend_kwargs,
41     show,
42 ):
43     """Matplotlib posterior plot."""
44     if ax is None:
45         _, ax = _create_axes_grid(
46             length_plotters,
47             rows,
48             cols,
49             figsize=figsize,
50             squeeze=False,
51             backend_kwargs=backend_kwargs,
52         )
53     idx = 0
54     for (var_name, selection, x), ax_ in zip(plotters, np.ravel(ax)):
55         _plot_posterior_op(
56             idx,
57             x.flatten(),
58             var_name,
59             selection,
60             ax=ax_,
61             bw=bw,
62             bins=bins,
63             kind=kind,
64             point_estimate=point_estimate,
65             round_to=round_to,
66             hdi_prob=hdi_prob,
67             multimodal=multimodal,
68             ref_val=ref_val,
69             rope=rope,
70             ax_labelsize=ax_labelsize,
71             xt_labelsize=xt_labelsize,
72             **kwargs
73         )
74         idx += 1
75         ax_.set_title(make_label(var_name, selection), fontsize=titlesize, wrap=True)
76 
77     if backend_show(show):
78         plt.show()
79 
80     return ax
81 
82 
83 def _plot_posterior_op(
84     idx,
85     values,
86     var_name,
87     selection,
88     ax,
89     bw,
90     linewidth,
91     bins,
92     kind,
93     point_estimate,
94     hdi_prob,
95     multimodal,
96     ref_val,
97     rope,
98     ax_labelsize,
99     xt_labelsize,
100     round_to: Optional[int] = None,
101     **kwargs
102 ):  # noqa: D202
103     """Artist to draw posterior."""
104 
105     def format_as_percent(x, round_to=0):
106         return "{0:.{1:d}f}%".format(100 * x, round_to)
107 
108     def display_ref_val():
109         if ref_val is None:
110             return
111         elif isinstance(ref_val, dict):
112             val = None
113             for sel in ref_val.get(var_name, []):
114                 if all(
115                     k in selection and selection[k] == v for k, v in sel.items() if k != "ref_val"
116                 ):
117                     val = sel["ref_val"]
118                     break
119             if val is None:
120                 return
121         elif isinstance(ref_val, list):
122             val = ref_val[idx]
123         elif isinstance(ref_val, Number):
124             val = ref_val
125         else:
126             raise ValueError(
127                 "Argument `ref_val` must be None, a constant, a list or a "
128                 'dictionary like {"var_name": [{"ref_val": ref_val}]}'
129             )
130         less_than_ref_probability = (values < val).mean()
131         greater_than_ref_probability = (values >= val).mean()
132         ref_in_posterior = "{} <{:g}< {}".format(
133             format_as_percent(less_than_ref_probability, 1),
134             val,
135             format_as_percent(greater_than_ref_probability, 1),
136         )
137         ax.axvline(val, ymin=0.05, ymax=0.75, color="C1", lw=linewidth, alpha=0.65)
138         ax.text(
139             values.mean(),
140             plot_height * 0.6,
141             ref_in_posterior,
142             size=ax_labelsize,
143             color="C1",
144             weight="semibold",
145             horizontalalignment="center",
146         )
147 
148     def display_rope():
149         if rope is None:
150             return
151         elif isinstance(rope, dict):
152             vals = None
153             for sel in rope.get(var_name, []):
154                 # pylint: disable=line-too-long
155                 if all(k in selection and selection[k] == v for k, v in sel.items() if k != "rope"):
156                     vals = sel["rope"]
157                     break
158             if vals is None:
159                 return
160         elif len(rope) == 2:
161             vals = rope
162         else:
163             raise ValueError(
164                 "Argument `rope` must be None, a dictionary like"
165                 '{"var_name": {"rope": (lo, hi)}}, or an'
166                 "iterable of length 2"
167             )
168 
169         ax.plot(
170             vals,
171             (plot_height * 0.02, plot_height * 0.02),
172             lw=linewidth * 5,
173             color="C2",
174             solid_capstyle="butt",
175             zorder=0,
176             alpha=0.7,
177         )
178         text_props = {"size": ax_labelsize, "horizontalalignment": "center", "color": "C2"}
179         ax.text(vals[0], plot_height * 0.2, vals[0], weight="semibold", **text_props)
180         ax.text(vals[1], plot_height * 0.2, vals[1], weight="semibold", **text_props)
181 
182     def display_point_estimate():
183         if not point_estimate:
184             return
185         point_value = calculate_point_estimate(point_estimate, values, bw)
186         sig_figs = format_sig_figs(point_value, round_to)
187         point_text = "{point_estimate}={point_value:.{sig_figs}g}".format(
188             point_estimate=point_estimate, point_value=point_value, sig_figs=sig_figs
189         )
190         ax.text(
191             point_value,
192             plot_height * 0.8,
193             point_text,
194             size=ax_labelsize,
195             horizontalalignment="center",
196         )
197 
198     def display_hdi():
199         # np.ndarray with 2 entries, min and max
200         # pylint: disable=line-too-long
201         hdi_probs = hdi(values, hdi_prob=hdi_prob, multimodal=multimodal)  # type: np.ndarray
202 
203         for hdi_i in np.atleast_2d(hdi_probs):
204             ax.plot(
205                 hdi_i,
206                 (plot_height * 0.02, plot_height * 0.02),
207                 lw=linewidth * 2,
208                 color="k",
209                 solid_capstyle="butt",
210             )
211             ax.text(
212                 hdi_i[0],
213                 plot_height * 0.07,
214                 round_num(hdi_i[0], round_to),
215                 size=ax_labelsize,
216                 horizontalalignment="center",
217             )
218             ax.text(
219                 hdi_i[1],
220                 plot_height * 0.07,
221                 round_num(hdi_i[1], round_to),
222                 size=ax_labelsize,
223                 horizontalalignment="center",
224             )
225             ax.text(
226                 (hdi_i[0] + hdi_i[1]) / 2,
227                 plot_height * 0.3,
228                 format_as_percent(hdi_prob) + " HDI",
229                 size=ax_labelsize,
230                 horizontalalignment="center",
231             )
232 
233     def format_axes():
234         ax.yaxis.set_ticks([])
235         ax.spines["top"].set_visible(False)
236         ax.spines["right"].set_visible(False)
237         ax.spines["left"].set_visible(False)
238         ax.spines["bottom"].set_visible(True)
239         ax.xaxis.set_ticks_position("bottom")
240         ax.tick_params(
241             axis="x", direction="out", width=1, length=3, color="0.5", labelsize=xt_labelsize
242         )
243         ax.spines["bottom"].set_color("0.5")
244 
245     if kind == "kde" and values.dtype.kind == "f":
246         kwargs.setdefault("linewidth", linewidth)
247         plot_kde(
248             values,
249             bw=bw,
250             fill_kwargs={"alpha": kwargs.pop("fill_alpha", 0)},
251             plot_kwargs=kwargs,
252             ax=ax,
253             rug=False,
254             show=False,
255         )
256     else:
257         if bins is None:
258             if values.dtype.kind == "i":
259                 xmin = values.min()
260                 xmax = values.max()
261                 bins = get_bins(values)
262                 ax.set_xlim(xmin - 0.5, xmax + 0.5)
263             else:
264                 bins = "auto"
265         kwargs.setdefault("align", "left")
266         kwargs.setdefault("color", "C0")
267         ax.hist(values, bins=bins, alpha=0.35, **kwargs)
268 
269     plot_height = ax.get_ylim()[1]
270 
271     format_axes()
272     if hdi_prob != "hide":
273         display_hdi()
274     display_point_estimate()
275     display_ref_val()
276     display_rope()
277
```
--- 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/backends/matplotlib/posteriorplot.py b/arviz/plots/backends/matplotlib/posteriorplot.py
--- a/arviz/plots/backends/matplotlib/posteriorplot.py
+++ b/arviz/plots/backends/matplotlib/posteriorplot.py
@@ -69,7 +69,7 @@
             rope=rope,
             ax_labelsize=ax_labelsize,
             xt_labelsize=xt_labelsize,
-            **kwargs
+            **kwargs,
         )
         idx += 1
         ax_.set_title(make_label(var_name, selection), fontsize=titlesize, wrap=True)
@@ -98,7 +98,7 @@
     ax_labelsize,
     xt_labelsize,
     round_to: Optional[int] = None,
-    **kwargs
+    **kwargs,
 ):  # noqa: D202
     """Artist to draw posterior."""
 
@@ -175,9 +175,23 @@
             zorder=0,
             alpha=0.7,
         )
-        text_props = {"size": ax_labelsize, "horizontalalignment": "center", "color": "C2"}
-        ax.text(vals[0], plot_height * 0.2, vals[0], weight="semibold", **text_props)
-        ax.text(vals[1], plot_height * 0.2, vals[1], weight="semibold", **text_props)
+        text_props = {"size": ax_labelsize, "color": "C2"}
+        ax.text(
+            vals[0],
+            plot_height * 0.2,
+            f"{vals[0]} ",
+            weight="semibold",
+            horizontalalignment="right",
+            **text_props,
+        )
+        ax.text(
+            vals[1],
+            plot_height * 0.2,
+            f" {vals[1]}",
+            weight="semibold",
+            horizontalalignment="left",
+            **text_props,
+        )
 
     def display_point_estimate():
         if not point_estimate:
@@ -211,16 +225,16 @@
             ax.text(
                 hdi_i[0],
                 plot_height * 0.07,
-                round_num(hdi_i[0], round_to),
+                round_num(hdi_i[0], round_to) + " ",
                 size=ax_labelsize,
-                horizontalalignment="center",
+                horizontalalignment="right",
             )
             ax.text(
                 hdi_i[1],
                 plot_height * 0.07,
-                round_num(hdi_i[1], round_to),
+                " " + round_num(hdi_i[1], round_to),
                 size=ax_labelsize,
-                horizontalalignment="center",
+                horizontalalignment="left",
             )
             ax.text(
                 (hdi_i[0] + hdi_i[1]) / 2,

{"golden_diff": "diff --git a/arviz/plots/backends/matplotlib/posteriorplot.py b/arviz/plots/backends/matplotlib/posteriorplot.py\n--- a/arviz/plots/backends/matplotlib/posteriorplot.py\n+++ b/arviz/plots/backends/matplotlib/posteriorplot.py\n@@ -69,7 +69,7 @@\n             rope=rope,\n             ax_labelsize=ax_labelsize,\n             xt_labelsize=xt_labelsize,\n-            **kwargs\n+            **kwargs,\n         )\n         idx += 1\n         ax_.set_title(make_label(var_name, selection), fontsize=titlesize, wrap=True)\n@@ -98,7 +98,7 @@\n     ax_labelsize,\n     xt_labelsize,\n     round_to: Optional[int] = None,\n-    **kwargs\n+    **kwargs,\n ):  # noqa: D202\n     \"\"\"Artist to draw posterior.\"\"\"\n \n@@ -175,9 +175,23 @@\n             zorder=0,\n             alpha=0.7,\n         )\n-        text_props = {\"size\": ax_labelsize, \"horizontalalignment\": \"center\", \"color\": \"C2\"}\n-        ax.text(vals[0], plot_height * 0.2, vals[0], weight=\"semibold\", **text_props)\n-        ax.text(vals[1], plot_height * 0.2, vals[1], weight=\"semibold\", **text_props)\n+        text_props = {\"size\": ax_labelsize, \"color\": \"C2\"}\n+        ax.text(\n+            vals[0],\n+            plot_height * 0.2,\n+            f\"{vals[0]} \",\n+            weight=\"semibold\",\n+            horizontalalignment=\"right\",\n+            **text_props,\n+        )\n+        ax.text(\n+            vals[1],\n+            plot_height * 0.2,\n+            f\" {vals[1]}\",\n+            weight=\"semibold\",\n+            horizontalalignment=\"left\",\n+            **text_props,\n+        )\n \n     def display_point_estimate():\n         if not point_estimate:\n@@ -211,16 +225,16 @@\n             ax.text(\n                 hdi_i[0],\n                 plot_height * 0.07,\n-                round_num(hdi_i[0], round_to),\n+                round_num(hdi_i[0], round_to) + \" \",\n                 size=ax_labelsize,\n-                horizontalalignment=\"center\",\n+                horizontalalignment=\"right\",\n             )\n             ax.text(\n                 hdi_i[1],\n                 plot_height * 0.07,\n-                round_num(hdi_i[1], round_to),\n+                \" \" + round_num(hdi_i[1], round_to),\n                 size=ax_labelsize,\n-                horizontalalignment=\"center\",\n+                horizontalalignment=\"left\",\n             )\n             ax.text(\n                 (hdi_i[0] + hdi_i[1]) / 2,\n", "issue": "HPD plot shows values over each other\nHey All,\r\n\r\nI am trying to figure out how to change the plot_posterior function to show the actual values.  In one of my plots, where it is small, I get numbers writing over each other.  Any help/advice?\r\n\r\n![image](https://user-images.githubusercontent.com/605973/85463990-c71ec780-b56c-11ea-95f6-3706e6ef72a1.png)\r\n\n", "before_files": [{"content": "\"\"\"Matplotlib Plot posterior densities.\"\"\"\nfrom typing import Optional\nfrom numbers import Number\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom . import backend_show\nfrom ....stats import hdi\nfrom ...kdeplot import plot_kde\nfrom ...plot_utils import (\n    make_label,\n    _create_axes_grid,\n    format_sig_figs,\n    round_num,\n    calculate_point_estimate,\n)\nfrom ....numeric_utils import get_bins\n\n\ndef plot_posterior(\n    ax,\n    length_plotters,\n    rows,\n    cols,\n    figsize,\n    plotters,\n    bw,\n    bins,\n    kind,\n    point_estimate,\n    round_to,\n    hdi_prob,\n    multimodal,\n    ref_val,\n    rope,\n    ax_labelsize,\n    xt_labelsize,\n    kwargs,\n    titlesize,\n    backend_kwargs,\n    show,\n):\n    \"\"\"Matplotlib posterior plot.\"\"\"\n    if ax is None:\n        _, ax = _create_axes_grid(\n            length_plotters,\n            rows,\n            cols,\n            figsize=figsize,\n            squeeze=False,\n            backend_kwargs=backend_kwargs,\n        )\n    idx = 0\n    for (var_name, selection, x), ax_ in zip(plotters, np.ravel(ax)):\n        _plot_posterior_op(\n            idx,\n            x.flatten(),\n            var_name,\n            selection,\n            ax=ax_,\n            bw=bw,\n            bins=bins,\n            kind=kind,\n            point_estimate=point_estimate,\n            round_to=round_to,\n            hdi_prob=hdi_prob,\n            multimodal=multimodal,\n            ref_val=ref_val,\n            rope=rope,\n            ax_labelsize=ax_labelsize,\n            xt_labelsize=xt_labelsize,\n            **kwargs\n        )\n        idx += 1\n        ax_.set_title(make_label(var_name, selection), fontsize=titlesize, wrap=True)\n\n    if backend_show(show):\n        plt.show()\n\n    return ax\n\n\ndef _plot_posterior_op(\n    idx,\n    values,\n    var_name,\n    selection,\n    ax,\n    bw,\n    linewidth,\n    bins,\n    kind,\n    point_estimate,\n    hdi_prob,\n    multimodal,\n    ref_val,\n    rope,\n    ax_labelsize,\n    xt_labelsize,\n    round_to: Optional[int] = None,\n    **kwargs\n):  # noqa: D202\n    \"\"\"Artist to draw posterior.\"\"\"\n\n    def format_as_percent(x, round_to=0):\n        return \"{0:.{1:d}f}%\".format(100 * x, round_to)\n\n    def display_ref_val():\n        if ref_val is None:\n            return\n        elif isinstance(ref_val, dict):\n            val = None\n            for sel in ref_val.get(var_name, []):\n                if all(\n                    k in selection and selection[k] == v for k, v in sel.items() if k != \"ref_val\"\n                ):\n                    val = sel[\"ref_val\"]\n                    break\n            if val is None:\n                return\n        elif isinstance(ref_val, list):\n            val = ref_val[idx]\n        elif isinstance(ref_val, Number):\n            val = ref_val\n        else:\n            raise ValueError(\n                \"Argument `ref_val` must be None, a constant, a list or a \"\n                'dictionary like {\"var_name\": [{\"ref_val\": ref_val}]}'\n            )\n        less_than_ref_probability = (values < val).mean()\n        greater_than_ref_probability = (values >= val).mean()\n        ref_in_posterior = \"{} <{:g}< {}\".format(\n            format_as_percent(less_than_ref_probability, 1),\n            val,\n            format_as_percent(greater_than_ref_probability, 1),\n        )\n        ax.axvline(val, ymin=0.05, ymax=0.75, color=\"C1\", lw=linewidth, alpha=0.65)\n        ax.text(\n            values.mean(),\n            plot_height * 0.6,\n            ref_in_posterior,\n            size=ax_labelsize,\n            color=\"C1\",\n            weight=\"semibold\",\n            horizontalalignment=\"center\",\n        )\n\n    def display_rope():\n        if rope is None:\n            return\n        elif isinstance(rope, dict):\n            vals = None\n            for sel in rope.get(var_name, []):\n                # pylint: disable=line-too-long\n                if all(k in selection and selection[k] == v for k, v in sel.items() if k != \"rope\"):\n                    vals = sel[\"rope\"]\n                    break\n            if vals is None:\n                return\n        elif len(rope) == 2:\n            vals = rope\n        else:\n            raise ValueError(\n                \"Argument `rope` must be None, a dictionary like\"\n                '{\"var_name\": {\"rope\": (lo, hi)}}, or an'\n                \"iterable of length 2\"\n            )\n\n        ax.plot(\n            vals,\n            (plot_height * 0.02, plot_height * 0.02),\n            lw=linewidth * 5,\n            color=\"C2\",\n            solid_capstyle=\"butt\",\n            zorder=0,\n            alpha=0.7,\n        )\n        text_props = {\"size\": ax_labelsize, \"horizontalalignment\": \"center\", \"color\": \"C2\"}\n        ax.text(vals[0], plot_height * 0.2, vals[0], weight=\"semibold\", **text_props)\n        ax.text(vals[1], plot_height * 0.2, vals[1], weight=\"semibold\", **text_props)\n\n    def display_point_estimate():\n        if not point_estimate:\n            return\n        point_value = calculate_point_estimate(point_estimate, values, bw)\n        sig_figs = format_sig_figs(point_value, round_to)\n        point_text = \"{point_estimate}={point_value:.{sig_figs}g}\".format(\n            point_estimate=point_estimate, point_value=point_value, sig_figs=sig_figs\n        )\n        ax.text(\n            point_value,\n            plot_height * 0.8,\n            point_text,\n            size=ax_labelsize,\n            horizontalalignment=\"center\",\n        )\n\n    def display_hdi():\n        # np.ndarray with 2 entries, min and max\n        # pylint: disable=line-too-long\n        hdi_probs = hdi(values, hdi_prob=hdi_prob, multimodal=multimodal)  # type: np.ndarray\n\n        for hdi_i in np.atleast_2d(hdi_probs):\n            ax.plot(\n                hdi_i,\n                (plot_height * 0.02, plot_height * 0.02),\n                lw=linewidth * 2,\n                color=\"k\",\n                solid_capstyle=\"butt\",\n            )\n            ax.text(\n                hdi_i[0],\n                plot_height * 0.07,\n                round_num(hdi_i[0], round_to),\n                size=ax_labelsize,\n                horizontalalignment=\"center\",\n            )\n            ax.text(\n                hdi_i[1],\n                plot_height * 0.07,\n                round_num(hdi_i[1], round_to),\n                size=ax_labelsize,\n                horizontalalignment=\"center\",\n            )\n            ax.text(\n                (hdi_i[0] + hdi_i[1]) / 2,\n                plot_height * 0.3,\n                format_as_percent(hdi_prob) + \" HDI\",\n                size=ax_labelsize,\n                horizontalalignment=\"center\",\n            )\n\n    def format_axes():\n        ax.yaxis.set_ticks([])\n        ax.spines[\"top\"].set_visible(False)\n        ax.spines[\"right\"].set_visible(False)\n        ax.spines[\"left\"].set_visible(False)\n        ax.spines[\"bottom\"].set_visible(True)\n        ax.xaxis.set_ticks_position(\"bottom\")\n        ax.tick_params(\n            axis=\"x\", direction=\"out\", width=1, length=3, color=\"0.5\", labelsize=xt_labelsize\n        )\n        ax.spines[\"bottom\"].set_color(\"0.5\")\n\n    if kind == \"kde\" and values.dtype.kind == \"f\":\n        kwargs.setdefault(\"linewidth\", linewidth)\n        plot_kde(\n            values,\n            bw=bw,\n            fill_kwargs={\"alpha\": kwargs.pop(\"fill_alpha\", 0)},\n            plot_kwargs=kwargs,\n            ax=ax,\n            rug=False,\n            show=False,\n        )\n    else:\n        if bins is None:\n            if values.dtype.kind == \"i\":\n                xmin = values.min()\n                xmax = values.max()\n                bins = get_bins(values)\n                ax.set_xlim(xmin - 0.5, xmax + 0.5)\n            else:\n                bins = \"auto\"\n        kwargs.setdefault(\"align\", \"left\")\n        kwargs.setdefault(\"color\", \"C0\")\n        ax.hist(values, bins=bins, alpha=0.35, **kwargs)\n\n    plot_height = ax.get_ylim()[1]\n\n    format_axes()\n    if hdi_prob != \"hide\":\n        display_hdi()\n    display_point_estimate()\n    display_ref_val()\n    display_rope()\n", "path": "arviz/plots/backends/matplotlib/posteriorplot.py"}], "after_files": [{"content": "\"\"\"Matplotlib Plot posterior densities.\"\"\"\nfrom typing import Optional\nfrom numbers import Number\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom . import backend_show\nfrom ....stats import hdi\nfrom ...kdeplot import plot_kde\nfrom ...plot_utils import (\n    make_label,\n    _create_axes_grid,\n    format_sig_figs,\n    round_num,\n    calculate_point_estimate,\n)\nfrom ....numeric_utils import get_bins\n\n\ndef plot_posterior(\n    ax,\n    length_plotters,\n    rows,\n    cols,\n    figsize,\n    plotters,\n    bw,\n    bins,\n    kind,\n    point_estimate,\n    round_to,\n    hdi_prob,\n    multimodal,\n    ref_val,\n    rope,\n    ax_labelsize,\n    xt_labelsize,\n    kwargs,\n    titlesize,\n    backend_kwargs,\n    show,\n):\n    \"\"\"Matplotlib posterior plot.\"\"\"\n    if ax is None:\n        _, ax = _create_axes_grid(\n            length_plotters,\n            rows,\n            cols,\n            figsize=figsize,\n            squeeze=False,\n            backend_kwargs=backend_kwargs,\n        )\n    idx = 0\n    for (var_name, selection, x), ax_ in zip(plotters, np.ravel(ax)):\n        _plot_posterior_op(\n            idx,\n            x.flatten(),\n            var_name,\n            selection,\n            ax=ax_,\n            bw=bw,\n            bins=bins,\n            kind=kind,\n            point_estimate=point_estimate,\n            round_to=round_to,\n            hdi_prob=hdi_prob,\n            multimodal=multimodal,\n            ref_val=ref_val,\n            rope=rope,\n            ax_labelsize=ax_labelsize,\n            xt_labelsize=xt_labelsize,\n            **kwargs,\n        )\n        idx += 1\n        ax_.set_title(make_label(var_name, selection), fontsize=titlesize, wrap=True)\n\n    if backend_show(show):\n        plt.show()\n\n    return ax\n\n\ndef _plot_posterior_op(\n    idx,\n    values,\n    var_name,\n    selection,\n    ax,\n    bw,\n    linewidth,\n    bins,\n    kind,\n    point_estimate,\n    hdi_prob,\n    multimodal,\n    ref_val,\n    rope,\n    ax_labelsize,\n    xt_labelsize,\n    round_to: Optional[int] = None,\n    **kwargs,\n):  # noqa: D202\n    \"\"\"Artist to draw posterior.\"\"\"\n\n    def format_as_percent(x, round_to=0):\n        return \"{0:.{1:d}f}%\".format(100 * x, round_to)\n\n    def display_ref_val():\n        if ref_val is None:\n            return\n        elif isinstance(ref_val, dict):\n            val = None\n            for sel in ref_val.get(var_name, []):\n                if all(\n                    k in selection and selection[k] == v for k, v in sel.items() if k != \"ref_val\"\n                ):\n                    val = sel[\"ref_val\"]\n                    break\n            if val is None:\n                return\n        elif isinstance(ref_val, list):\n            val = ref_val[idx]\n        elif isinstance(ref_val, Number):\n            val = ref_val\n        else:\n            raise ValueError(\n                \"Argument `ref_val` must be None, a constant, a list or a \"\n                'dictionary like {\"var_name\": [{\"ref_val\": ref_val}]}'\n            )\n        less_than_ref_probability = (values < val).mean()\n        greater_than_ref_probability = (values >= val).mean()\n        ref_in_posterior = \"{} <{:g}< {}\".format(\n            format_as_percent(less_than_ref_probability, 1),\n            val,\n            format_as_percent(greater_than_ref_probability, 1),\n        )\n        ax.axvline(val, ymin=0.05, ymax=0.75, color=\"C1\", lw=linewidth, alpha=0.65)\n        ax.text(\n            values.mean(),\n            plot_height * 0.6,\n            ref_in_posterior,\n            size=ax_labelsize,\n            color=\"C1\",\n            weight=\"semibold\",\n            horizontalalignment=\"center\",\n        )\n\n    def display_rope():\n        if rope is None:\n            return\n        elif isinstance(rope, dict):\n            vals = None\n            for sel in rope.get(var_name, []):\n                # pylint: disable=line-too-long\n                if all(k in selection and selection[k] == v for k, v in sel.items() if k != \"rope\"):\n                    vals = sel[\"rope\"]\n                    break\n            if vals is None:\n                return\n        elif len(rope) == 2:\n            vals = rope\n        else:\n            raise ValueError(\n                \"Argument `rope` must be None, a dictionary like\"\n                '{\"var_name\": {\"rope\": (lo, hi)}}, or an'\n                \"iterable of length 2\"\n            )\n\n        ax.plot(\n            vals,\n            (plot_height * 0.02, plot_height * 0.02),\n            lw=linewidth * 5,\n            color=\"C2\",\n            solid_capstyle=\"butt\",\n            zorder=0,\n            alpha=0.7,\n        )\n        text_props = {\"size\": ax_labelsize, \"color\": \"C2\"}\n        ax.text(\n            vals[0],\n            plot_height * 0.2,\n            f\"{vals[0]} \",\n            weight=\"semibold\",\n            horizontalalignment=\"right\",\n            **text_props,\n        )\n        ax.text(\n            vals[1],\n            plot_height * 0.2,\n            f\" {vals[1]}\",\n            weight=\"semibold\",\n            horizontalalignment=\"left\",\n            **text_props,\n        )\n\n    def display_point_estimate():\n        if not point_estimate:\n            return\n        point_value = calculate_point_estimate(point_estimate, values, bw)\n        sig_figs = format_sig_figs(point_value, round_to)\n        point_text = \"{point_estimate}={point_value:.{sig_figs}g}\".format(\n            point_estimate=point_estimate, point_value=point_value, sig_figs=sig_figs\n        )\n        ax.text(\n            point_value,\n            plot_height * 0.8,\n            point_text,\n            size=ax_labelsize,\n            horizontalalignment=\"center\",\n        )\n\n    def display_hdi():\n        # np.ndarray with 2 entries, min and max\n        # pylint: disable=line-too-long\n        hdi_probs = hdi(values, hdi_prob=hdi_prob, multimodal=multimodal)  # type: np.ndarray\n\n        for hdi_i in np.atleast_2d(hdi_probs):\n            ax.plot(\n                hdi_i,\n                (plot_height * 0.02, plot_height * 0.02),\n                lw=linewidth * 2,\n                color=\"k\",\n                solid_capstyle=\"butt\",\n            )\n            ax.text(\n                hdi_i[0],\n                plot_height * 0.07,\n                round_num(hdi_i[0], round_to) + \" \",\n                size=ax_labelsize,\n                horizontalalignment=\"right\",\n            )\n            ax.text(\n                hdi_i[1],\n                plot_height * 0.07,\n                \" \" + round_num(hdi_i[1], round_to),\n                size=ax_labelsize,\n                horizontalalignment=\"left\",\n            )\n            ax.text(\n                (hdi_i[0] + hdi_i[1]) / 2,\n                plot_height * 0.3,\n                format_as_percent(hdi_prob) + \" HDI\",\n                size=ax_labelsize,\n                horizontalalignment=\"center\",\n            )\n\n    def format_axes():\n        ax.yaxis.set_ticks([])\n        ax.spines[\"top\"].set_visible(False)\n        ax.spines[\"right\"].set_visible(False)\n        ax.spines[\"left\"].set_visible(False)\n        ax.spines[\"bottom\"].set_visible(True)\n        ax.xaxis.set_ticks_position(\"bottom\")\n        ax.tick_params(\n            axis=\"x\", direction=\"out\", width=1, length=3, color=\"0.5\", labelsize=xt_labelsize\n        )\n        ax.spines[\"bottom\"].set_color(\"0.5\")\n\n    if kind == \"kde\" and values.dtype.kind == \"f\":\n        kwargs.setdefault(\"linewidth\", linewidth)\n        plot_kde(\n            values,\n            bw=bw,\n            fill_kwargs={\"alpha\": kwargs.pop(\"fill_alpha\", 0)},\n            plot_kwargs=kwargs,\n            ax=ax,\n            rug=False,\n            show=False,\n        )\n    else:\n        if bins is None:\n            if values.dtype.kind == \"i\":\n                xmin = values.min()\n                xmax = values.max()\n                bins = get_bins(values)\n                ax.set_xlim(xmin - 0.5, xmax + 0.5)\n            else:\n                bins = \"auto\"\n        kwargs.setdefault(\"align\", \"left\")\n        kwargs.setdefault(\"color\", \"C0\")\n        ax.hist(values, bins=bins, alpha=0.35, **kwargs)\n\n    plot_height = ax.get_ylim()[1]\n\n    format_axes()\n    if hdi_prob != \"hide\":\n        display_hdi()\n    display_point_estimate()\n    display_ref_val()\n    display_rope()\n", "path": "arviz/plots/backends/matplotlib/posteriorplot.py"}]}