Skip to content

Commit afe8083

Browse files
fix histogram marginal/facet rule order
1 parent 6fc1362 commit afe8083

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/python/plotly/plotly/express/_core.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -924,13 +924,6 @@ def apply_default_cascade(args):
924924
"longdashdot",
925925
]
926926

927-
# If both marginals and faceting are specified, faceting wins
928-
if args.get("facet_col", None) is not None and args.get("marginal_y", None):
929-
args["marginal_y"] = None
930-
931-
if args.get("facet_row", None) is not None and args.get("marginal_x", None):
932-
args["marginal_x"] = None
933-
934927

935928
def _check_name_not_reserved(field_name, reserved_names):
936929
if field_name not in reserved_names:
@@ -1775,6 +1768,14 @@ def infer_config(args, constructor, trace_patch, layout_patch):
17751768
args[position] = args["marginal"]
17761769
args[other_position] = None
17771770

1771+
# If both marginals and faceting are specified, faceting wins
1772+
if args.get("facet_col", None) is not None and args.get("marginal_y", None):
1773+
args["marginal_y"] = None
1774+
1775+
if args.get("facet_row", None) is not None and args.get("marginal_x", None):
1776+
args["marginal_x"] = None
1777+
1778+
# facet_col_wrap only works if no marginals or row faceting is used
17781779
if (
17791780
args.get("marginal_x", None) is not None
17801781
or args.get("marginal_y", None) is not None

packages/python/plotly/plotly/tests/test_core/test_px/test_facets.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ def test_facets_with_marginals():
5151

5252
fig = px.histogram(df, x="total_bill", facet_col="sex", marginal="rug")
5353
assert len(fig.data) == 4
54-
# fig = px.histogram(df, x="total_bill", facet_row="sex", marginal="rug")
55-
# assert len(fig.data) == 2 buggy
54+
fig = px.histogram(df, x="total_bill", facet_row="sex", marginal="rug")
55+
assert len(fig.data) == 2
56+
57+
fig = px.histogram(df, y="total_bill", facet_col="sex", marginal="rug")
58+
assert len(fig.data) == 2
59+
fig = px.histogram(df, y="total_bill", facet_row="sex", marginal="rug")
60+
assert len(fig.data) == 4
5661

5762
fig = px.scatter(df, x="total_bill", y="tip", facet_col="sex", marginal_x="rug")
5863
assert len(fig.data) == 4

0 commit comments

Comments
 (0)