Repository: arviz-devs/arviz

Issue:
Variable names in element labels for `plot_forest` should be optional
Currently, creating a forest plot with `plot_forest` uses `<var name> <coordinate name>` as the scheme for labels on the y-axis. This creates a slew of repeated variable names in the labels, which I would guess is almost always undesirable (particularly when you have nice element labels as coordinates in the dataset):

<img width="508" alt="Screen Shot 2021-01-27 at 1 02 58 PM" src="https://user-images.githubusercontent.com/81476/106040982-d6389b80-60a0-11eb-9f8a-be4a4a579062.png">

There should be excluded by default, and turned on with a `include_var_names=True` (or similar) argument. 

Alternatively, the first coordinate could include the variable name, and then exclude it for subsequent ones.


Discussion:
What would probably be even better is if we displayed the var_name + coords
only once and then only the coords. Not sure how much harder that would be
🤔

Le mer. 27 janv. 2021 à 20:12, Chris Fonnesbeck <notifications@github.com>
a écrit :

> Currently, creating a forest plot with plot_forest uses <var name>
> <coordinate name> as the scheme for labels on the y-axis. This creates a
> slew of repeated variable names in the labels, which I would guess is
> almost always undesirable (particularly when you have nice element labels
> as coordinates in the dataset):
>
> [image: Screen Shot 2021-01-27 at 1 02 58 PM]
> <https://user-images.githubusercontent.com/81476/106040982-d6389b80-60a0-11eb-9f8a-be4a4a579062.png>
>
> There should be excluded by default, and turned on with a
> include_var_names=True (or similar) argument.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/arviz-devs/arviz/issues/1524>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AHIJMTAY5ZJVX4DWSKSPUXLS4BQSDANCNFSM4WVZC55A>
> .
>


Resolving patch:
diff --git a/arviz/plots/backends/bokeh/forestplot.py b/arviz/plots/backends/bokeh/forestplot.py
--- a/arviz/plots/backends/bokeh/forestplot.py
+++ b/arviz/plots/backends/bokeh/forestplot.py
@@ -572,9 +572,16 @@ def iterator(self):
                     skip_dims=skip_dims,
                     reverse_selections=True,
                 )
-                for _, selection, values in datum_iter:
+                datum_list = list(datum_iter)
+                for _, selection, values in datum_list:
                     selection_list.append(selection)
-                    label = make_label(self.var_name, selection, position="beside")
+                    if not selection:
+                        var_name = self.var_name
+                    elif len(selection_list) == len(datum_list):
+                        var_name = self.var_name + ":"
+                    else:
+                        var_name = ""
+                    label = make_label(var_name, selection, position="beside")
                     if label not in label_dict:
                         label_dict[label] = OrderedDict()
                     if name not in label_dict[label]:
diff --git a/arviz/plots/backends/matplotlib/forestplot.py b/arviz/plots/backends/matplotlib/forestplot.py
--- a/arviz/plots/backends/matplotlib/forestplot.py
+++ b/arviz/plots/backends/matplotlib/forestplot.py
@@ -514,9 +514,16 @@ def iterator(self):
                     skip_dims=skip_dims,
                     reverse_selections=True,
                 )
-                for _, selection, values in datum_iter:
+                datum_list = list(datum_iter)
+                for _, selection, values in datum_list:
                     selection_list.append(selection)
-                    label = make_label(self.var_name, selection, position="beside")
+                    if not selection:
+                        var_name = self.var_name
+                    elif not len(selection_list) % len(datum_list):
+                        var_name = self.var_name + ":"
+                    else:
+                        var_name = ""
+                    label = make_label(var_name, selection, position="beside")
                     if label not in label_dict:
                         label_dict[label] = OrderedDict()
                     if name not in label_dict[label]:


Test patch: