Skip to content

Commit c74e723

Browse files
fix for odd box/violin spacing when axis matches color
1 parent 87d9984 commit c74e723

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def violin(
386386
color_discrete_sequence=None,
387387
color_discrete_map={},
388388
orientation=None,
389-
violinmode="group",
389+
violinmode=None,
390390
log_x=False,
391391
log_y=False,
392392
range_x=None,
@@ -433,7 +433,7 @@ def box(
433433
color_discrete_sequence=None,
434434
color_discrete_map={},
435435
orientation=None,
436-
boxmode="group",
436+
boxmode=None,
437437
log_x=False,
438438
log_y=False,
439439
range_x=None,
@@ -483,7 +483,7 @@ def strip(
483483
color_discrete_sequence=None,
484484
color_discrete_map={},
485485
orientation=None,
486-
stripmode="group",
486+
stripmode=None,
487487
log_x=False,
488488
log_y=False,
489489
range_x=None,

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ def aggfunc_continuous(x):
11941194
return args
11951195

11961196

1197-
def infer_config(args, constructor, trace_patch):
1197+
def infer_config(args, constructor, trace_patch, layout_patch):
11981198
# Declare all supported attributes, across all plot types
11991199
attrables = (
12001200
["x", "y", "z", "a", "b", "c", "r", "theta", "size", "dimensions"]
@@ -1246,6 +1246,16 @@ def infer_config(args, constructor, trace_patch):
12461246
trace_patch["bingroup"] = "x" if orientation == "v" else "y"
12471247
trace_patch["orientation"] = args["orientation"]
12481248

1249+
if constructor in [go.Violin, go.Box]:
1250+
mode = "boxmode" if constructor == go.Box else "violinmode"
1251+
if layout_patch[mode] is None and args["color"] is not None:
1252+
if args["y"] == args["color"] and args["orientation"] == "h":
1253+
layout_patch[mode] = "overlay"
1254+
elif args["x"] == args["color"] and args["orientation"] == "v":
1255+
layout_patch[mode] = "overlay"
1256+
if layout_patch[mode] is None:
1257+
layout_patch[mode] = "group"
1258+
12491259
attrs = [k for k in attrables if k in args]
12501260
grouped_attrs = []
12511261

@@ -1396,7 +1406,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
13961406
apply_default_cascade(args)
13971407

13981408
args, trace_specs, grouped_mappings, sizeref, show_colorbar = infer_config(
1399-
args, constructor, trace_patch
1409+
args, constructor, trace_patch, layout_patch
14001410
)
14011411
grouper = [x.grouper or one_group for x in grouped_mappings] or [one_group]
14021412
grouped = args["data_frame"].groupby(grouper, sort=False)

0 commit comments

Comments
 (0)