Skip to content

Commit a60d313

Browse files
pie category_orders
1 parent dcc4a6d commit a60d313

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Diff for: CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
### Added
88

99
- `pattern_shape` options now available in `px.timeline()` [#3774](https://github.com/plotly/plotly.py/pull/3774)
10-
- `facet_*` options now available in `px.pie()` and `px.funnel_area()` [#3775](https://github.com/plotly/plotly.py/pull/3775)
10+
- `facet_*` and `category_orders` now available in `px.pie()` [#3775](https://github.com/plotly/plotly.py/pull/3775)
1111

1212
## [5.8.2] - 2022-06-10
1313

Diff for: packages/python/plotly/plotly/express/_chart_types.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ def pie(
14621462
hover_name=None,
14631463
hover_data=None,
14641464
custom_data=None,
1465+
category_orders=None,
14651466
labels=None,
14661467
title=None,
14671468
template=None,
@@ -1694,11 +1695,6 @@ def funnel_area(
16941695
names=None,
16951696
values=None,
16961697
color=None,
1697-
facet_row=None,
1698-
facet_col=None,
1699-
facet_col_wrap=0,
1700-
facet_row_spacing=None,
1701-
facet_col_spacing=None,
17021698
color_discrete_sequence=None,
17031699
color_discrete_map=None,
17041700
hover_name=None,

Diff for: packages/python/plotly/plotly/express/_core.py

+18
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,22 @@ def process_dataframe_timeline(args):
16861686
return args
16871687

16881688

1689+
def process_dataframe_pie(args, trace_patch):
1690+
names = args.get("names")
1691+
if names is None:
1692+
return args, trace_patch
1693+
order_in = args["category_orders"].get(names, {}).copy()
1694+
if not order_in:
1695+
return args, trace_patch
1696+
df = args["data_frame"]
1697+
trace_patch["sort"] = False
1698+
trace_patch["direction"] = "clockwise"
1699+
uniques = list(df[names].unique())
1700+
order = [x for x in OrderedDict.fromkeys(list(order_in) + uniques) if x in uniques]
1701+
args["data_frame"] = df.set_index(names).loc[order].reset_index()
1702+
return args, trace_patch
1703+
1704+
16891705
def infer_config(args, constructor, trace_patch, layout_patch):
16901706
attrs = [k for k in direct_attrables + array_attrables if k in args]
16911707
grouped_attrs = []
@@ -1948,6 +1964,8 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
19481964
args = build_dataframe(args, constructor)
19491965
if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None:
19501966
args = process_dataframe_hierarchy(args)
1967+
if constructor in [go.Pie, go.Funnelarea]:
1968+
args, trace_patch = process_dataframe_pie(args, trace_patch)
19511969
if constructor == "timeline":
19521970
constructor = go.Bar
19531971
args = process_dataframe_timeline(args)

0 commit comments

Comments
 (0)