We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
plot_compare issue with pWAIC
The plot_compare method seems to add the pWAIC values to the in-sample deviance to get WAIC values regardless of scale (deviance or log). Shouldn't the pWAIC be subtracted in the log scale, where a higher score is better? Otherwise, for example with two models m1 and m2 with the same in-sample deviance of 20: if m1 has pWAIC of 10, m2 has pWAIC of 5 then m1 WAIC is 30 and m2 WAIC is 25 so m1 is preferred. However, with the same in-sample deviance the model with the lower pWAIC should be preferred i.e. m2.

Example from my work:

![image](https://user-images.githubusercontent.com/8579413/87334769-28530e80-c50d-11ea-96c0-6cf2e240e346.png)

I might be getting confused about this and my example isn't well explained, sorry.

--- 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/bokeh/compareplot.py`
Content:
```
1 """Bokeh Compareplot."""
2 from bokeh.models import Span
3 
4 from ...plot_utils import _scale_fig_size
5 from .. import show_layout
6 from . import backend_kwarg_defaults, create_axes_grid
7 
8 
9 def plot_compare(
10     ax,
11     comp_df,
12     figsize,
13     plot_ic_diff,
14     plot_standard_error,
15     insample_dev,
16     yticks_pos,
17     yticks_labels,
18     plot_kwargs,
19     textsize,
20     information_criterion,
21     step,
22     backend_kwargs,
23     show,
24 ):
25     """Bokeh compareplot."""
26     if backend_kwargs is None:
27         backend_kwargs = {}
28 
29     backend_kwargs = {
30         **backend_kwarg_defaults(),
31         **backend_kwargs,
32     }
33 
34     figsize, _, _, _, line_width, _ = _scale_fig_size(figsize, textsize, 1, 1)
35 
36     if ax is None:
37         ax = create_axes_grid(
38             1,
39             figsize=figsize,
40             squeeze=True,
41             backend_kwargs=backend_kwargs,
42         )
43 
44     yticks_pos = list(yticks_pos)
45 
46     if plot_ic_diff:
47         yticks_labels[0] = comp_df.index[0]
48         yticks_labels[2::2] = comp_df.index[1:]
49 
50         ax.yaxis.ticker = yticks_pos
51         ax.yaxis.major_label_overrides = {
52             dtype(key): value
53             for key, value in zip(yticks_pos, yticks_labels)
54             for dtype in (int, float)
55             if (dtype(key) - key == 0)
56         }
57 
58         # create the coordinates for the errorbars
59         err_xs = []
60         err_ys = []
61 
62         for x, y, xerr in zip(
63             comp_df[information_criterion].iloc[1:], yticks_pos[1::2], comp_df.dse[1:]
64         ):
65             err_xs.append((x - xerr, x + xerr))
66             err_ys.append((y, y))
67 
68         # plot them
69         ax.triangle(
70             comp_df[information_criterion].iloc[1:],
71             yticks_pos[1::2],
72             line_color=plot_kwargs.get("color_dse", "grey"),
73             fill_color=plot_kwargs.get("color_dse", "grey"),
74             line_width=2,
75             size=6,
76         )
77         ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get("color_dse", "grey"))
78 
79     else:
80         yticks_labels = comp_df.index
81         ax.yaxis.ticker = yticks_pos[::2]
82         ax.yaxis.major_label_overrides = {
83             key: value for key, value in zip(yticks_pos[::2], yticks_labels)
84         }
85 
86     ax.circle(
87         comp_df[information_criterion],
88         yticks_pos[::2],
89         line_color=plot_kwargs.get("color_ic", "black"),
90         fill_color=None,
91         line_width=2,
92         size=6,
93     )
94 
95     if plot_standard_error:
96         # create the coordinates for the errorbars
97         err_xs = []
98         err_ys = []
99 
100         for x, y, xerr in zip(comp_df[information_criterion], yticks_pos[::2], comp_df.se):
101             err_xs.append((x - xerr, x + xerr))
102             err_ys.append((y, y))
103 
104         # plot them
105         ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get("color_ic", "black"))
106 
107     if insample_dev:
108         ax.circle(
109             comp_df[information_criterion] - (2 * comp_df["p_" + information_criterion]),
110             yticks_pos[::2],
111             line_color=plot_kwargs.get("color_insample_dev", "black"),
112             fill_color=plot_kwargs.get("color_insample_dev", "black"),
113             line_width=2,
114             size=6,
115         )
116 
117     vline = Span(
118         location=comp_df[information_criterion].iloc[0],
119         dimension="height",
120         line_color=plot_kwargs.get("color_ls_min_ic", "grey"),
121         line_width=line_width,
122         line_dash=plot_kwargs.get("ls_min_ic", "dashed"),
123     )
124 
125     ax.renderers.append(vline)
126 
127     scale_col = information_criterion + "_scale"
128     if scale_col in comp_df:
129         scale = comp_df[scale_col].iloc[0].capitalize()
130     else:
131         scale = "Deviance"
132     ax.xaxis.axis_label = scale
133     ax.y_range._property_values["start"] = -1 + step  # pylint: disable=protected-access
134     ax.y_range._property_values["end"] = 0 - step  # pylint: disable=protected-access
135 
136     show_layout(ax, show)
137 
138     return ax
139
```

Path: `arviz/plots/backends/matplotlib/compareplot.py`
Content:
```
1 """Matplotlib Compareplot."""
2 import matplotlib.pyplot as plt
3 
4 from ...plot_utils import _scale_fig_size
5 from . import backend_kwarg_defaults, backend_show, create_axes_grid
6 
7 
8 def plot_compare(
9     ax,
10     comp_df,
11     figsize,
12     plot_ic_diff,
13     plot_standard_error,
14     insample_dev,
15     yticks_pos,
16     yticks_labels,
17     plot_kwargs,
18     information_criterion,
19     textsize,
20     step,
21     backend_kwargs,
22     show,
23 ):
24     """Matplotlib compare plot."""
25     if backend_kwargs is None:
26         backend_kwargs = {}
27 
28     backend_kwargs = {
29         **backend_kwarg_defaults(),
30         **backend_kwargs,
31     }
32 
33     if figsize is None:
34         figsize = (6, len(comp_df))
35 
36     figsize, ax_labelsize, _, xt_labelsize, linewidth, _ = _scale_fig_size(figsize, textsize, 1, 1)
37 
38     backend_kwargs.setdefault("figsize", figsize)
39     backend_kwargs["squeeze"] = True
40 
41     if ax is None:
42         _, ax = create_axes_grid(1, backend_kwargs=backend_kwargs)
43 
44     if plot_ic_diff:
45         yticks_labels[0] = comp_df.index[0]
46         yticks_labels[2::2] = comp_df.index[1:]
47         ax.set_yticks(yticks_pos)
48         ax.errorbar(
49             x=comp_df[information_criterion].iloc[1:],
50             y=yticks_pos[1::2],
51             xerr=comp_df.dse[1:],
52             color=plot_kwargs.get("color_dse", "grey"),
53             fmt=plot_kwargs.get("marker_dse", "^"),
54             mew=linewidth,
55             elinewidth=linewidth,
56         )
57 
58     else:
59         yticks_labels = comp_df.index
60         ax.set_yticks(yticks_pos[::2])
61 
62     if plot_standard_error:
63         ax.errorbar(
64             x=comp_df[information_criterion],
65             y=yticks_pos[::2],
66             xerr=comp_df.se,
67             color=plot_kwargs.get("color_ic", "k"),
68             fmt=plot_kwargs.get("marker_ic", "o"),
69             mfc="None",
70             mew=linewidth,
71             lw=linewidth,
72         )
73     else:
74         ax.plot(
75             comp_df[information_criterion],
76             yticks_pos[::2],
77             color=plot_kwargs.get("color_ic", "k"),
78             marker=plot_kwargs.get("marker_ic", "o"),
79             mfc="None",
80             mew=linewidth,
81             lw=0,
82         )
83 
84     if insample_dev:
85         ax.plot(
86             comp_df[information_criterion] - (2 * comp_df["p_" + information_criterion]),
87             yticks_pos[::2],
88             color=plot_kwargs.get("color_insample_dev", "k"),
89             marker=plot_kwargs.get("marker_insample_dev", "o"),
90             mew=linewidth,
91             lw=0,
92         )
93 
94     ax.axvline(
95         comp_df[information_criterion].iloc[0],
96         ls=plot_kwargs.get("ls_min_ic", "--"),
97         color=plot_kwargs.get("color_ls_min_ic", "grey"),
98         lw=linewidth,
99     )
100 
101     scale_col = information_criterion + "_scale"
102     if scale_col in comp_df:
103         scale = comp_df[scale_col].iloc[0].capitalize()
104     else:
105         scale = "Deviance"
106     ax.set_xlabel(scale, fontsize=ax_labelsize)
107     ax.set_yticklabels(yticks_labels)
108     ax.set_ylim(-1 + step, 0 - step)
109     ax.tick_params(labelsize=xt_labelsize)
110 
111     if backend_show(show):
112         plt.show()
113 
114     return ax
115
```
--- 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/bokeh/compareplot.py b/arviz/plots/backends/bokeh/compareplot.py
--- a/arviz/plots/backends/bokeh/compareplot.py
+++ b/arviz/plots/backends/bokeh/compareplot.py
@@ -105,8 +105,16 @@
         ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get("color_ic", "black"))
 
     if insample_dev:
+        scale = comp_df[f"{information_criterion}_scale"][0]
+        p_ic = comp_df[f"p_{information_criterion}"]
+        if scale == "log":
+            correction = p_ic
+        elif scale == "negative_log":
+            correction = -p_ic
+        elif scale == "deviance":
+            correction = -(2 * p_ic)
         ax.circle(
-            comp_df[information_criterion] - (2 * comp_df["p_" + information_criterion]),
+            comp_df[information_criterion] + correction,
             yticks_pos[::2],
             line_color=plot_kwargs.get("color_insample_dev", "black"),
             fill_color=plot_kwargs.get("color_insample_dev", "black"),
diff --git a/arviz/plots/backends/matplotlib/compareplot.py b/arviz/plots/backends/matplotlib/compareplot.py
--- a/arviz/plots/backends/matplotlib/compareplot.py
+++ b/arviz/plots/backends/matplotlib/compareplot.py
@@ -82,8 +82,16 @@
         )
 
     if insample_dev:
+        scale = comp_df[f"{information_criterion}_scale"][0]
+        p_ic = comp_df[f"p_{information_criterion}"]
+        if scale == "log":
+            correction = p_ic
+        elif scale == "negative_log":
+            correction = -p_ic
+        elif scale == "deviance":
+            correction = -(2 * p_ic)
         ax.plot(
-            comp_df[information_criterion] - (2 * comp_df["p_" + information_criterion]),
+            comp_df[information_criterion] + correction,
             yticks_pos[::2],
             color=plot_kwargs.get("color_insample_dev", "k"),
             marker=plot_kwargs.get("marker_insample_dev", "o"),

{"golden_diff": "diff --git a/arviz/plots/backends/bokeh/compareplot.py b/arviz/plots/backends/bokeh/compareplot.py\n--- a/arviz/plots/backends/bokeh/compareplot.py\n+++ b/arviz/plots/backends/bokeh/compareplot.py\n@@ -105,8 +105,16 @@\n         ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get(\"color_ic\", \"black\"))\n \n     if insample_dev:\n+        scale = comp_df[f\"{information_criterion}_scale\"][0]\n+        p_ic = comp_df[f\"p_{information_criterion}\"]\n+        if scale == \"log\":\n+            correction = p_ic\n+        elif scale == \"negative_log\":\n+            correction = -p_ic\n+        elif scale == \"deviance\":\n+            correction = -(2 * p_ic)\n         ax.circle(\n-            comp_df[information_criterion] - (2 * comp_df[\"p_\" + information_criterion]),\n+            comp_df[information_criterion] + correction,\n             yticks_pos[::2],\n             line_color=plot_kwargs.get(\"color_insample_dev\", \"black\"),\n             fill_color=plot_kwargs.get(\"color_insample_dev\", \"black\"),\ndiff --git a/arviz/plots/backends/matplotlib/compareplot.py b/arviz/plots/backends/matplotlib/compareplot.py\n--- a/arviz/plots/backends/matplotlib/compareplot.py\n+++ b/arviz/plots/backends/matplotlib/compareplot.py\n@@ -82,8 +82,16 @@\n         )\n \n     if insample_dev:\n+        scale = comp_df[f\"{information_criterion}_scale\"][0]\n+        p_ic = comp_df[f\"p_{information_criterion}\"]\n+        if scale == \"log\":\n+            correction = p_ic\n+        elif scale == \"negative_log\":\n+            correction = -p_ic\n+        elif scale == \"deviance\":\n+            correction = -(2 * p_ic)\n         ax.plot(\n-            comp_df[information_criterion] - (2 * comp_df[\"p_\" + information_criterion]),\n+            comp_df[information_criterion] + correction,\n             yticks_pos[::2],\n             color=plot_kwargs.get(\"color_insample_dev\", \"k\"),\n             marker=plot_kwargs.get(\"marker_insample_dev\", \"o\"),\n", "issue": "plot_compare issue with pWAIC\nThe plot_compare method seems to add the pWAIC values to the in-sample deviance to get WAIC values regardless of scale (deviance or log). Shouldn't the pWAIC be subtracted in the log scale, where a higher score is better? Otherwise, for example with two models m1 and m2 with the same in-sample deviance of 20: if m1 has pWAIC of 10, m2 has pWAIC of 5 then m1 WAIC is 30 and m2 WAIC is 25 so m1 is preferred. However, with the same in-sample deviance the model with the lower pWAIC should be preferred i.e. m2.\r\n\r\nExample from my work:\r\n\r\n![image](https://user-images.githubusercontent.com/8579413/87334769-28530e80-c50d-11ea-96c0-6cf2e240e346.png)\r\n\r\nI might be getting confused about this and my example isn't well explained, sorry.\n", "before_files": [{"content": "\"\"\"Bokeh Compareplot.\"\"\"\nfrom bokeh.models import Span\n\nfrom ...plot_utils import _scale_fig_size\nfrom .. import show_layout\nfrom . import backend_kwarg_defaults, create_axes_grid\n\n\ndef plot_compare(\n    ax,\n    comp_df,\n    figsize,\n    plot_ic_diff,\n    plot_standard_error,\n    insample_dev,\n    yticks_pos,\n    yticks_labels,\n    plot_kwargs,\n    textsize,\n    information_criterion,\n    step,\n    backend_kwargs,\n    show,\n):\n    \"\"\"Bokeh compareplot.\"\"\"\n    if backend_kwargs is None:\n        backend_kwargs = {}\n\n    backend_kwargs = {\n        **backend_kwarg_defaults(),\n        **backend_kwargs,\n    }\n\n    figsize, _, _, _, line_width, _ = _scale_fig_size(figsize, textsize, 1, 1)\n\n    if ax is None:\n        ax = create_axes_grid(\n            1,\n            figsize=figsize,\n            squeeze=True,\n            backend_kwargs=backend_kwargs,\n        )\n\n    yticks_pos = list(yticks_pos)\n\n    if plot_ic_diff:\n        yticks_labels[0] = comp_df.index[0]\n        yticks_labels[2::2] = comp_df.index[1:]\n\n        ax.yaxis.ticker = yticks_pos\n        ax.yaxis.major_label_overrides = {\n            dtype(key): value\n            for key, value in zip(yticks_pos, yticks_labels)\n            for dtype in (int, float)\n            if (dtype(key) - key == 0)\n        }\n\n        # create the coordinates for the errorbars\n        err_xs = []\n        err_ys = []\n\n        for x, y, xerr in zip(\n            comp_df[information_criterion].iloc[1:], yticks_pos[1::2], comp_df.dse[1:]\n        ):\n            err_xs.append((x - xerr, x + xerr))\n            err_ys.append((y, y))\n\n        # plot them\n        ax.triangle(\n            comp_df[information_criterion].iloc[1:],\n            yticks_pos[1::2],\n            line_color=plot_kwargs.get(\"color_dse\", \"grey\"),\n            fill_color=plot_kwargs.get(\"color_dse\", \"grey\"),\n            line_width=2,\n            size=6,\n        )\n        ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get(\"color_dse\", \"grey\"))\n\n    else:\n        yticks_labels = comp_df.index\n        ax.yaxis.ticker = yticks_pos[::2]\n        ax.yaxis.major_label_overrides = {\n            key: value for key, value in zip(yticks_pos[::2], yticks_labels)\n        }\n\n    ax.circle(\n        comp_df[information_criterion],\n        yticks_pos[::2],\n        line_color=plot_kwargs.get(\"color_ic\", \"black\"),\n        fill_color=None,\n        line_width=2,\n        size=6,\n    )\n\n    if plot_standard_error:\n        # create the coordinates for the errorbars\n        err_xs = []\n        err_ys = []\n\n        for x, y, xerr in zip(comp_df[information_criterion], yticks_pos[::2], comp_df.se):\n            err_xs.append((x - xerr, x + xerr))\n            err_ys.append((y, y))\n\n        # plot them\n        ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get(\"color_ic\", \"black\"))\n\n    if insample_dev:\n        ax.circle(\n            comp_df[information_criterion] - (2 * comp_df[\"p_\" + information_criterion]),\n            yticks_pos[::2],\n            line_color=plot_kwargs.get(\"color_insample_dev\", \"black\"),\n            fill_color=plot_kwargs.get(\"color_insample_dev\", \"black\"),\n            line_width=2,\n            size=6,\n        )\n\n    vline = Span(\n        location=comp_df[information_criterion].iloc[0],\n        dimension=\"height\",\n        line_color=plot_kwargs.get(\"color_ls_min_ic\", \"grey\"),\n        line_width=line_width,\n        line_dash=plot_kwargs.get(\"ls_min_ic\", \"dashed\"),\n    )\n\n    ax.renderers.append(vline)\n\n    scale_col = information_criterion + \"_scale\"\n    if scale_col in comp_df:\n        scale = comp_df[scale_col].iloc[0].capitalize()\n    else:\n        scale = \"Deviance\"\n    ax.xaxis.axis_label = scale\n    ax.y_range._property_values[\"start\"] = -1 + step  # pylint: disable=protected-access\n    ax.y_range._property_values[\"end\"] = 0 - step  # pylint: disable=protected-access\n\n    show_layout(ax, show)\n\n    return ax\n", "path": "arviz/plots/backends/bokeh/compareplot.py"}, {"content": "\"\"\"Matplotlib Compareplot.\"\"\"\nimport matplotlib.pyplot as plt\n\nfrom ...plot_utils import _scale_fig_size\nfrom . import backend_kwarg_defaults, backend_show, create_axes_grid\n\n\ndef plot_compare(\n    ax,\n    comp_df,\n    figsize,\n    plot_ic_diff,\n    plot_standard_error,\n    insample_dev,\n    yticks_pos,\n    yticks_labels,\n    plot_kwargs,\n    information_criterion,\n    textsize,\n    step,\n    backend_kwargs,\n    show,\n):\n    \"\"\"Matplotlib compare plot.\"\"\"\n    if backend_kwargs is None:\n        backend_kwargs = {}\n\n    backend_kwargs = {\n        **backend_kwarg_defaults(),\n        **backend_kwargs,\n    }\n\n    if figsize is None:\n        figsize = (6, len(comp_df))\n\n    figsize, ax_labelsize, _, xt_labelsize, linewidth, _ = _scale_fig_size(figsize, textsize, 1, 1)\n\n    backend_kwargs.setdefault(\"figsize\", figsize)\n    backend_kwargs[\"squeeze\"] = True\n\n    if ax is None:\n        _, ax = create_axes_grid(1, backend_kwargs=backend_kwargs)\n\n    if plot_ic_diff:\n        yticks_labels[0] = comp_df.index[0]\n        yticks_labels[2::2] = comp_df.index[1:]\n        ax.set_yticks(yticks_pos)\n        ax.errorbar(\n            x=comp_df[information_criterion].iloc[1:],\n            y=yticks_pos[1::2],\n            xerr=comp_df.dse[1:],\n            color=plot_kwargs.get(\"color_dse\", \"grey\"),\n            fmt=plot_kwargs.get(\"marker_dse\", \"^\"),\n            mew=linewidth,\n            elinewidth=linewidth,\n        )\n\n    else:\n        yticks_labels = comp_df.index\n        ax.set_yticks(yticks_pos[::2])\n\n    if plot_standard_error:\n        ax.errorbar(\n            x=comp_df[information_criterion],\n            y=yticks_pos[::2],\n            xerr=comp_df.se,\n            color=plot_kwargs.get(\"color_ic\", \"k\"),\n            fmt=plot_kwargs.get(\"marker_ic\", \"o\"),\n            mfc=\"None\",\n            mew=linewidth,\n            lw=linewidth,\n        )\n    else:\n        ax.plot(\n            comp_df[information_criterion],\n            yticks_pos[::2],\n            color=plot_kwargs.get(\"color_ic\", \"k\"),\n            marker=plot_kwargs.get(\"marker_ic\", \"o\"),\n            mfc=\"None\",\n            mew=linewidth,\n            lw=0,\n        )\n\n    if insample_dev:\n        ax.plot(\n            comp_df[information_criterion] - (2 * comp_df[\"p_\" + information_criterion]),\n            yticks_pos[::2],\n            color=plot_kwargs.get(\"color_insample_dev\", \"k\"),\n            marker=plot_kwargs.get(\"marker_insample_dev\", \"o\"),\n            mew=linewidth,\n            lw=0,\n        )\n\n    ax.axvline(\n        comp_df[information_criterion].iloc[0],\n        ls=plot_kwargs.get(\"ls_min_ic\", \"--\"),\n        color=plot_kwargs.get(\"color_ls_min_ic\", \"grey\"),\n        lw=linewidth,\n    )\n\n    scale_col = information_criterion + \"_scale\"\n    if scale_col in comp_df:\n        scale = comp_df[scale_col].iloc[0].capitalize()\n    else:\n        scale = \"Deviance\"\n    ax.set_xlabel(scale, fontsize=ax_labelsize)\n    ax.set_yticklabels(yticks_labels)\n    ax.set_ylim(-1 + step, 0 - step)\n    ax.tick_params(labelsize=xt_labelsize)\n\n    if backend_show(show):\n        plt.show()\n\n    return ax\n", "path": "arviz/plots/backends/matplotlib/compareplot.py"}], "after_files": [{"content": "\"\"\"Bokeh Compareplot.\"\"\"\nfrom bokeh.models import Span\n\nfrom ...plot_utils import _scale_fig_size\nfrom .. import show_layout\nfrom . import backend_kwarg_defaults, create_axes_grid\n\n\ndef plot_compare(\n    ax,\n    comp_df,\n    figsize,\n    plot_ic_diff,\n    plot_standard_error,\n    insample_dev,\n    yticks_pos,\n    yticks_labels,\n    plot_kwargs,\n    textsize,\n    information_criterion,\n    step,\n    backend_kwargs,\n    show,\n):\n    \"\"\"Bokeh compareplot.\"\"\"\n    if backend_kwargs is None:\n        backend_kwargs = {}\n\n    backend_kwargs = {\n        **backend_kwarg_defaults(),\n        **backend_kwargs,\n    }\n\n    figsize, _, _, _, line_width, _ = _scale_fig_size(figsize, textsize, 1, 1)\n\n    if ax is None:\n        ax = create_axes_grid(\n            1,\n            figsize=figsize,\n            squeeze=True,\n            backend_kwargs=backend_kwargs,\n        )\n\n    yticks_pos = list(yticks_pos)\n\n    if plot_ic_diff:\n        yticks_labels[0] = comp_df.index[0]\n        yticks_labels[2::2] = comp_df.index[1:]\n\n        ax.yaxis.ticker = yticks_pos\n        ax.yaxis.major_label_overrides = {\n            dtype(key): value\n            for key, value in zip(yticks_pos, yticks_labels)\n            for dtype in (int, float)\n            if (dtype(key) - key == 0)\n        }\n\n        # create the coordinates for the errorbars\n        err_xs = []\n        err_ys = []\n\n        for x, y, xerr in zip(\n            comp_df[information_criterion].iloc[1:], yticks_pos[1::2], comp_df.dse[1:]\n        ):\n            err_xs.append((x - xerr, x + xerr))\n            err_ys.append((y, y))\n\n        # plot them\n        ax.triangle(\n            comp_df[information_criterion].iloc[1:],\n            yticks_pos[1::2],\n            line_color=plot_kwargs.get(\"color_dse\", \"grey\"),\n            fill_color=plot_kwargs.get(\"color_dse\", \"grey\"),\n            line_width=2,\n            size=6,\n        )\n        ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get(\"color_dse\", \"grey\"))\n\n    else:\n        yticks_labels = comp_df.index\n        ax.yaxis.ticker = yticks_pos[::2]\n        ax.yaxis.major_label_overrides = {\n            key: value for key, value in zip(yticks_pos[::2], yticks_labels)\n        }\n\n    ax.circle(\n        comp_df[information_criterion],\n        yticks_pos[::2],\n        line_color=plot_kwargs.get(\"color_ic\", \"black\"),\n        fill_color=None,\n        line_width=2,\n        size=6,\n    )\n\n    if plot_standard_error:\n        # create the coordinates for the errorbars\n        err_xs = []\n        err_ys = []\n\n        for x, y, xerr in zip(comp_df[information_criterion], yticks_pos[::2], comp_df.se):\n            err_xs.append((x - xerr, x + xerr))\n            err_ys.append((y, y))\n\n        # plot them\n        ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get(\"color_ic\", \"black\"))\n\n    if insample_dev:\n        scale = comp_df[f\"{information_criterion}_scale\"][0]\n        p_ic = comp_df[f\"p_{information_criterion}\"]\n        if scale == \"log\":\n            correction = p_ic\n        elif scale == \"negative_log\":\n            correction = -p_ic\n        elif scale == \"deviance\":\n            correction = -(2 * p_ic)\n        ax.circle(\n            comp_df[information_criterion] + correction,\n            yticks_pos[::2],\n            line_color=plot_kwargs.get(\"color_insample_dev\", \"black\"),\n            fill_color=plot_kwargs.get(\"color_insample_dev\", \"black\"),\n            line_width=2,\n            size=6,\n        )\n\n    vline = Span(\n        location=comp_df[information_criterion].iloc[0],\n        dimension=\"height\",\n        line_color=plot_kwargs.get(\"color_ls_min_ic\", \"grey\"),\n        line_width=line_width,\n        line_dash=plot_kwargs.get(\"ls_min_ic\", \"dashed\"),\n    )\n\n    ax.renderers.append(vline)\n\n    scale_col = information_criterion + \"_scale\"\n    if scale_col in comp_df:\n        scale = comp_df[scale_col].iloc[0].capitalize()\n    else:\n        scale = \"Deviance\"\n    ax.xaxis.axis_label = scale\n    ax.y_range._property_values[\"start\"] = -1 + step  # pylint: disable=protected-access\n    ax.y_range._property_values[\"end\"] = 0 - step  # pylint: disable=protected-access\n\n    show_layout(ax, show)\n\n    return ax\n", "path": "arviz/plots/backends/bokeh/compareplot.py"}, {"content": "\"\"\"Matplotlib Compareplot.\"\"\"\nimport matplotlib.pyplot as plt\n\nfrom ...plot_utils import _scale_fig_size\nfrom . import backend_kwarg_defaults, backend_show, create_axes_grid\n\n\ndef plot_compare(\n    ax,\n    comp_df,\n    figsize,\n    plot_ic_diff,\n    plot_standard_error,\n    insample_dev,\n    yticks_pos,\n    yticks_labels,\n    plot_kwargs,\n    information_criterion,\n    textsize,\n    step,\n    backend_kwargs,\n    show,\n):\n    \"\"\"Matplotlib compare plot.\"\"\"\n    if backend_kwargs is None:\n        backend_kwargs = {}\n\n    backend_kwargs = {\n        **backend_kwarg_defaults(),\n        **backend_kwargs,\n    }\n\n    if figsize is None:\n        figsize = (6, len(comp_df))\n\n    figsize, ax_labelsize, _, xt_labelsize, linewidth, _ = _scale_fig_size(figsize, textsize, 1, 1)\n\n    backend_kwargs.setdefault(\"figsize\", figsize)\n    backend_kwargs[\"squeeze\"] = True\n\n    if ax is None:\n        _, ax = create_axes_grid(1, backend_kwargs=backend_kwargs)\n\n    if plot_ic_diff:\n        yticks_labels[0] = comp_df.index[0]\n        yticks_labels[2::2] = comp_df.index[1:]\n        ax.set_yticks(yticks_pos)\n        ax.errorbar(\n            x=comp_df[information_criterion].iloc[1:],\n            y=yticks_pos[1::2],\n            xerr=comp_df.dse[1:],\n            color=plot_kwargs.get(\"color_dse\", \"grey\"),\n            fmt=plot_kwargs.get(\"marker_dse\", \"^\"),\n            mew=linewidth,\n            elinewidth=linewidth,\n        )\n\n    else:\n        yticks_labels = comp_df.index\n        ax.set_yticks(yticks_pos[::2])\n\n    if plot_standard_error:\n        ax.errorbar(\n            x=comp_df[information_criterion],\n            y=yticks_pos[::2],\n            xerr=comp_df.se,\n            color=plot_kwargs.get(\"color_ic\", \"k\"),\n            fmt=plot_kwargs.get(\"marker_ic\", \"o\"),\n            mfc=\"None\",\n            mew=linewidth,\n            lw=linewidth,\n        )\n    else:\n        ax.plot(\n            comp_df[information_criterion],\n            yticks_pos[::2],\n            color=plot_kwargs.get(\"color_ic\", \"k\"),\n            marker=plot_kwargs.get(\"marker_ic\", \"o\"),\n            mfc=\"None\",\n            mew=linewidth,\n            lw=0,\n        )\n\n    if insample_dev:\n        scale = comp_df[f\"{information_criterion}_scale\"][0]\n        p_ic = comp_df[f\"p_{information_criterion}\"]\n        if scale == \"log\":\n            correction = p_ic\n        elif scale == \"negative_log\":\n            correction = -p_ic\n        elif scale == \"deviance\":\n            correction = -(2 * p_ic)\n        ax.plot(\n            comp_df[information_criterion] + correction,\n            yticks_pos[::2],\n            color=plot_kwargs.get(\"color_insample_dev\", \"k\"),\n            marker=plot_kwargs.get(\"marker_insample_dev\", \"o\"),\n            mew=linewidth,\n            lw=0,\n        )\n\n    ax.axvline(\n        comp_df[information_criterion].iloc[0],\n        ls=plot_kwargs.get(\"ls_min_ic\", \"--\"),\n        color=plot_kwargs.get(\"color_ls_min_ic\", \"grey\"),\n        lw=linewidth,\n    )\n\n    scale_col = information_criterion + \"_scale\"\n    if scale_col in comp_df:\n        scale = comp_df[scale_col].iloc[0].capitalize()\n    else:\n        scale = \"Deviance\"\n    ax.set_xlabel(scale, fontsize=ax_labelsize)\n    ax.set_yticklabels(yticks_labels)\n    ax.set_ylim(-1 + step, 0 - step)\n    ax.tick_params(labelsize=xt_labelsize)\n\n    if backend_show(show):\n        plt.show()\n\n    return ax\n", "path": "arviz/plots/backends/matplotlib/compareplot.py"}]}