diff --git a/CHANGELOG.md b/CHANGELOG.md index fe4557c8256..635e9424994 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_*` 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 f7b0d7b88ab..dc2b22599e5 100644 --- a/packages/python/plotly/plotly/express/_chart_types.py +++ b/packages/python/plotly/plotly/express/_chart_types.py @@ -1452,11 +1452,17 @@ 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, hover_data=None, custom_data=None, + category_orders=None, labels=None, title=None, template=None, diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index f4aa02cdc21..99a4c2a3701 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]: + args, trace_patch = process_dataframe_pie(args, trace_patch) if constructor == "timeline": constructor = go.Bar args = process_dataframe_timeline(args)