From f7d537cb4e51a9282c670c7b3394cb4be4edbc79 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Thu, 9 Jan 2020 14:38:24 -0500 Subject: [PATCH 1/3] use legend titles in PX --- doc/python/plotly-express.md | 9 ++++----- packages/python/plotly/plotly/express/_core.py | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/doc/python/plotly-express.md b/doc/python/plotly-express.md index ddb985d982b..42095c7ca82 100644 --- a/doc/python/plotly-express.md +++ b/doc/python/plotly-express.md @@ -5,8 +5,8 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.1" - jupytext_version: 1.1.1 + format_version: '1.2' + jupytext_version: 1.3.1 kernelspec: display_name: Python 3 language: python @@ -20,10 +20,9 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.7.3 + version: 3.6.8 plotly: - description: - Plotly Express is a terse, consistent, high-level API for rapid data + description: Plotly Express is a terse, consistent, high-level API for rapid data exploration and figure generation. display_as: file_settings language: python diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 3911641f06e..9843c7e1da9 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1197,7 +1197,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): trace_name_labels[key] = str(val) if m.variable == "animation_frame": frame_name = val - trace_name = ", ".join(k + "=" + v for k, v in trace_name_labels.items()) + trace_name = ", ".join(trace_name_labels.values()) if frame_name not in trace_names_by_frame: trace_names_by_frame[frame_name] = set() trace_names = trace_names_by_frame[frame_name] @@ -1346,7 +1346,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): for v in ["title", "height", "width"]: if args[v]: layout_patch[v] = args[v] - layout_patch["legend"] = {"tracegroupgap": 0} + layout_patch["legend"] = dict(tracegroupgap=0, title=", ".join(trace_name_labels)) if "title" not in layout_patch and args["template"].layout.margin.t is None: layout_patch["margin"] = {"t": 60} if ( From b57def20a84f20419c7a905876c72c17c89b335d Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Thu, 9 Jan 2020 15:02:30 -0500 Subject: [PATCH 2/3] fix tests --- .../python/plotly/plotly/express/_core.py | 12 ++++++---- .../plotly/tests/test_core/test_px/test_px.py | 22 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 9843c7e1da9..c8cb3789f80 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1184,20 +1184,22 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): nrows = ncols = 1 col_labels = [] row_labels = [] + trace_name_labels = [] for group_name in sorted_group_names: group = grouped.get_group(group_name if len(group_name) > 1 else group_name[0]) mapping_labels = OrderedDict() - trace_name_labels = OrderedDict() frame_name = "" + trace_name = [] for col, val, m in zip(grouper, group_name, grouped_mappings): if col != one_group: key = get_label(args, col) mapping_labels[key] = str(val) if m.show_in_trace_name: - trace_name_labels[key] = str(val) + trace_name_labels.append(key) + trace_name.append(str(val)) if m.variable == "animation_frame": frame_name = val - trace_name = ", ".join(trace_name_labels.values()) + trace_name = ", ".join(trace_name) if frame_name not in trace_names_by_frame: trace_names_by_frame[frame_name] = set() trace_names = trace_names_by_frame[frame_name] @@ -1346,7 +1348,9 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): for v in ["title", "height", "width"]: if args[v]: layout_patch[v] = args[v] - layout_patch["legend"] = dict(tracegroupgap=0, title=", ".join(trace_name_labels)) + layout_patch["legend"] = dict(tracegroupgap=0) + if trace_name_labels: + layout_patch["legend"]["title"] = ", ".join(trace_name_labels) if "title" not in layout_patch and args["template"].layout.margin.t is None: layout_patch["margin"] = {"t": 60} if ( diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py index 736c74461c6..99284e02ba2 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py @@ -63,18 +63,18 @@ def test_labels(): facet_col="day", color="size", symbol="sex", - labels={c: c[::-1] for c in tips.columns}, + labels={c: c.upper() for c in tips.columns}, ) - assert "xes" in fig.data[0].hovertemplate - assert "llib_latot" in fig.data[0].hovertemplate - assert "ezis" in fig.data[0].hovertemplate - assert "yad" in fig.data[0].hovertemplate - assert "emit" in fig.data[0].hovertemplate - assert fig.data[0].name.startswith("xes") - assert fig.layout.xaxis.title.text == "llib_latot" - assert fig.layout.coloraxis.colorbar.title.text == "ezis" - assert fig.layout.annotations[0].text.startswith("yad") - assert fig.layout.annotations[4].text.startswith("emit") + assert "SEX" in fig.data[0].hovertemplate + assert "TOTAL_BILL" in fig.data[0].hovertemplate + assert "SIZE" in fig.data[0].hovertemplate + assert "DAY" in fig.data[0].hovertemplate + assert "TIME" in fig.data[0].hovertemplate + assert fig.layout.legend.title.text.startswith("SEX") + assert fig.layout.xaxis.title.text == "TOTAL_BILL" + assert fig.layout.coloraxis.colorbar.title.text == "SIZE" + assert fig.layout.annotations[0].text.startswith("DAY") + assert fig.layout.annotations[4].text.startswith("TIME") def test_px_templates(): From 80fe6975dd28fa096983b976c70e4b9f13f3d060 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Thu, 9 Jan 2020 15:19:33 -0500 Subject: [PATCH 3/3] fix tests --- packages/python/plotly/plotly/express/_core.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index c8cb3789f80..1d919123c65 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1184,22 +1184,21 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): nrows = ncols = 1 col_labels = [] row_labels = [] - trace_name_labels = [] + trace_name_labels = None for group_name in sorted_group_names: group = grouped.get_group(group_name if len(group_name) > 1 else group_name[0]) mapping_labels = OrderedDict() + trace_name_labels = OrderedDict() frame_name = "" - trace_name = [] for col, val, m in zip(grouper, group_name, grouped_mappings): if col != one_group: key = get_label(args, col) mapping_labels[key] = str(val) if m.show_in_trace_name: - trace_name_labels.append(key) - trace_name.append(str(val)) + trace_name_labels[key] = str(val) if m.variable == "animation_frame": frame_name = val - trace_name = ", ".join(trace_name) + trace_name = ", ".join(trace_name_labels.values()) if frame_name not in trace_names_by_frame: trace_names_by_frame[frame_name] = set() trace_names = trace_names_by_frame[frame_name] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy