Skip to content

Commit a4b9887

Browse files
Merge pull request #3775 from plotly/pie_facets
Pie facets
2 parents e962890 + 0fdaab1 commit a4b9887

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

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

88
### Added
99

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

1213
### Updated
1314

packages/python/plotly/plotly/express/_chart_types.py

+6
Original file line numberDiff line numberDiff line change
@@ -1452,11 +1452,17 @@ def pie(
14521452
names=None,
14531453
values=None,
14541454
color=None,
1455+
facet_row=None,
1456+
facet_col=None,
1457+
facet_col_wrap=0,
1458+
facet_row_spacing=None,
1459+
facet_col_spacing=None,
14551460
color_discrete_sequence=None,
14561461
color_discrete_map=None,
14571462
hover_name=None,
14581463
hover_data=None,
14591464
custom_data=None,
1465+
category_orders=None,
14601466
labels=None,
14611467
title=None,
14621468
template=None,

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]:
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)