Skip to content

Commit 18e1c00

Browse files
clean up default {}
1 parent f3ca0fc commit 18e1c00

File tree

1 file changed

+44
-45
lines changed
  • packages/python/plotly/plotly/express

1 file changed

+44
-45
lines changed

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

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,46 +1216,6 @@ def infer_config(args, constructor, trace_patch, layout_patch):
12161216
if constructor in [go.Treemap, go.Sunburst] and args["path"] is not None:
12171217
args = process_dataframe_hierarchy(args)
12181218

1219-
if "orientation" in args:
1220-
has_x = args["x"] is not None
1221-
has_y = args["y"] is not None
1222-
if args["orientation"] is None:
1223-
if constructor in [go.Histogram, go.Scatter]:
1224-
if has_y and not has_x:
1225-
args["orientation"] = "h"
1226-
elif constructor in [go.Violin, go.Box, go.Bar, go.Funnel]:
1227-
if has_x and not has_y:
1228-
args["orientation"] = "h"
1229-
1230-
if args["orientation"] is None and has_x and has_y:
1231-
x_is_continuous = _is_continuous(args["data_frame"], args["x"])
1232-
y_is_continuous = _is_continuous(args["data_frame"], args["y"])
1233-
if x_is_continuous and not y_is_continuous:
1234-
args["orientation"] = "h"
1235-
if y_is_continuous and not x_is_continuous:
1236-
args["orientation"] = "v"
1237-
1238-
if args["orientation"] is None:
1239-
args["orientation"] = "v"
1240-
1241-
if constructor == go.Histogram:
1242-
orientation = args["orientation"]
1243-
nbins = args["nbins"]
1244-
trace_patch["nbinsx"] = nbins if orientation == "v" else None
1245-
trace_patch["nbinsy"] = None if orientation == "v" else nbins
1246-
trace_patch["bingroup"] = "x" if orientation == "v" else "y"
1247-
trace_patch["orientation"] = args["orientation"]
1248-
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-
12591219
attrs = [k for k in attrables if k in args]
12601220
grouped_attrs = []
12611221

@@ -1309,8 +1269,45 @@ def infer_config(args, constructor, trace_patch, layout_patch):
13091269
if "symbol" in args:
13101270
grouped_attrs.append("marker.symbol")
13111271

1312-
# Compute final trace patch
1313-
trace_patch = trace_patch.copy()
1272+
if "orientation" in args:
1273+
has_x = args["x"] is not None
1274+
has_y = args["y"] is not None
1275+
if args["orientation"] is None:
1276+
if constructor in [go.Histogram, go.Scatter]:
1277+
if has_y and not has_x:
1278+
args["orientation"] = "h"
1279+
elif constructor in [go.Violin, go.Box, go.Bar, go.Funnel]:
1280+
if has_x and not has_y:
1281+
args["orientation"] = "h"
1282+
1283+
if args["orientation"] is None and has_x and has_y:
1284+
x_is_continuous = _is_continuous(args["data_frame"], args["x"])
1285+
y_is_continuous = _is_continuous(args["data_frame"], args["y"])
1286+
if x_is_continuous and not y_is_continuous:
1287+
args["orientation"] = "h"
1288+
if y_is_continuous and not x_is_continuous:
1289+
args["orientation"] = "v"
1290+
1291+
if args["orientation"] is None:
1292+
args["orientation"] = "v"
1293+
1294+
if constructor == go.Histogram:
1295+
orientation = args["orientation"]
1296+
nbins = args["nbins"]
1297+
trace_patch["nbinsx"] = nbins if orientation == "v" else None
1298+
trace_patch["nbinsy"] = None if orientation == "v" else nbins
1299+
trace_patch["bingroup"] = "x" if orientation == "v" else "y"
1300+
trace_patch["orientation"] = args["orientation"]
1301+
1302+
if constructor in [go.Violin, go.Box]:
1303+
mode = "boxmode" if constructor == go.Box else "violinmode"
1304+
if layout_patch[mode] is None and args["color"] is not None:
1305+
if args["y"] == args["color"] and args["orientation"] == "h":
1306+
layout_patch[mode] = "overlay"
1307+
elif args["x"] == args["color"] and args["orientation"] == "v":
1308+
layout_patch[mode] = "overlay"
1309+
if layout_patch[mode] is None:
1310+
layout_patch[mode] = "group"
13141311

13151312
if constructor in [go.Histogram2d, go.Densitymapbox]:
13161313
show_colorbar = True
@@ -1358,7 +1355,7 @@ def infer_config(args, constructor, trace_patch, layout_patch):
13581355

13591356
# Create trace specs
13601357
trace_specs = make_trace_spec(args, constructor, attrs, trace_patch)
1361-
return args, trace_specs, grouped_mappings, sizeref, show_colorbar
1358+
return trace_specs, grouped_mappings, sizeref, show_colorbar
13621359

13631360

13641361
def get_orderings(args, grouper, grouped):
@@ -1402,10 +1399,12 @@ def get_orderings(args, grouper, grouped):
14021399
return orders, group_names, group_values
14031400

14041401

1405-
def make_figure(args, constructor, trace_patch={}, layout_patch={}):
1402+
def make_figure(args, constructor, trace_patch=None, layout_patch=None):
1403+
trace_patch = trace_patch or {}
1404+
layout_patch = layout_patch or {}
14061405
apply_default_cascade(args)
14071406

1408-
args, trace_specs, grouped_mappings, sizeref, show_colorbar = infer_config(
1407+
trace_specs, grouped_mappings, sizeref, show_colorbar = infer_config(
14091408
args, constructor, trace_patch, layout_patch
14101409
)
14111410
grouper = [x.grouper or one_group for x in grouped_mappings] or [one_group]

0 commit comments

Comments
 (0)