From ecca18911ea4adf9b0af9db439c74775fdcd8112 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sat, 11 Jun 2022 15:55:14 -0400 Subject: [PATCH 1/4] px facetting for pie and funnel_area --- packages/python/plotly/plotly/express/_chart_types.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index f7b0d7b88ab..60e3379f6f6 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -1452,6 +1452,11 @@ def pie( names=None, values=None, color=None, + facet_row=None, + facet_col=None, + facet_col_wrap=0, + facet_row_spacing=None, + facet_col_spacing=None, color_discrete_sequence=None, color_discrete_map=None, hover_name=None, @@ -1689,6 +1694,11 @@ def funnel_area( names=None, values=None, color=None, + facet_row=None, + facet_col=None, + facet_col_wrap=0, + facet_row_spacing=None, + facet_col_spacing=None, color_discrete_sequence=None, color_discrete_map=None, hover_name=None, From dcc4a6d7680a7560aab579218d74a3d6f75780c9 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sat, 11 Jun 2022 15:56:25 -0400 Subject: [PATCH 2/4] px facetting for pie and funnel_area --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe4557c8256..270eb7b3e8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - - `pattern_shape` options now available in `px.timeline()` + - `pattern_shape` options now available in `px.timeline()` [#3774](https://github.com/plotly/plotly.py/pull/3774) + - `facet_*` options now available in `px.pie()` and `px.funnel_area()` [#3775](https://github.com/plotly/plotly.py/pull/3775) ## [5.8.2] - 2022-06-10 From a60d313832a733d74b8e17f4bd7d5de39affe7d3 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Mon, 13 Jun 2022 08:21:08 -0400 Subject: [PATCH 3/4] pie category_orders --- CHANGELOG.md | 2 +- .../plotly/plotly/express/_chart_types.py | 6 +----- packages/python/plotly/plotly/express/_core.py | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 270eb7b3e8f..635e9424994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - `pattern_shape` options now available in `px.timeline()` [#3774](https://github.com/plotly/plotly.py/pull/3774) - - `facet_*` options now available in `px.pie()` and `px.funnel_area()` [#3775](https://github.com/plotly/plotly.py/pull/3775) + - `facet_*` and `category_orders` now available in `px.pie()` [#3775](https://github.com/plotly/plotly.py/pull/3775) ## [5.8.2] - 2022-06-10 diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py index 60e3379f6f6..dc2b22599e5 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -1462,6 +1462,7 @@ def pie( hover_name=None, hover_data=None, custom_data=None, + category_orders=None, labels=None, title=None, template=None, @@ -1694,11 +1695,6 @@ def funnel_area( names=None, values=None, color=None, - facet_row=None, - facet_col=None, - facet_col_wrap=0, - facet_row_spacing=None, - facet_col_spacing=None, color_discrete_sequence=None, color_discrete_map=None, hover_name=None, diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index f4aa02cdc21..e4b5b040ac0 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1686,6 +1686,22 @@ def process_dataframe_timeline(args): return args +def process_dataframe_pie(args, trace_patch): + names = args.get("names") + if names is None: + return args, trace_patch + order_in = args["category_orders"].get(names, {}).copy() + if not order_in: + return args, trace_patch + df = args["data_frame"] + trace_patch["sort"] = False + trace_patch["direction"] = "clockwise" + uniques = list(df[names].unique()) + order = [x for x in OrderedDict.fromkeys(list(order_in) + uniques) if x in uniques] + args["data_frame"] = df.set_index(names).loc[order].reset_index() + return args, trace_patch + + def infer_config(args, constructor, trace_patch, layout_patch): attrs = [k for k in direct_attrables + array_attrables if k in args] grouped_attrs = [] @@ -1948,6 +1964,8 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None): args = build_dataframe(args, constructor) if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None: args = process_dataframe_hierarchy(args) + if constructor in [go.Pie, go.Funnelarea]: + args, trace_patch = process_dataframe_pie(args, trace_patch) if constructor == "timeline": constructor = go.Bar args = process_dataframe_timeline(args) From 0fdaab13d072b89fb670f18e6f612ee59907be4b Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Mon, 13 Jun 2022 08:21:28 -0400 Subject: [PATCH 4/4] pie category_orders --- packages/python/plotly/plotly/express/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index e4b5b040ac0..99a4c2a3701 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1964,7 +1964,7 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None): args = build_dataframe(args, constructor) if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None: args = process_dataframe_hierarchy(args) - if constructor in [go.Pie, go.Funnelarea]: + if constructor in [go.Pie]: args, trace_patch = process_dataframe_pie(args, trace_patch) if constructor == "timeline": constructor = go.Bar