@@ -92,6 +92,10 @@ def get_label(args, column):
92
92
return column
93
93
94
94
95
+ def _is_continuous (df , col_name ):
96
+ return df [col_name ].dtype .kind in "ifc"
97
+
98
+
95
99
def get_decorated_label (args , column , role ):
96
100
label = get_label (args , column )
97
101
if "histfunc" in args and (
@@ -188,7 +192,7 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
188
192
if ((not attr_value ) or (name in attr_value ))
189
193
and (
190
194
trace_spec .constructor != go .Parcoords
191
- or args ["data_frame" ][ name ]. dtype . kind in "ifc"
195
+ or _is_continuous ( args ["data_frame" ], name )
192
196
)
193
197
and (
194
198
trace_spec .constructor != go .Parcats
@@ -1161,7 +1165,7 @@ def aggfunc_discrete(x):
1161
1165
agg_f [count_colname ] = "sum"
1162
1166
1163
1167
if args ["color" ]:
1164
- if df [ args ["color" ]]. dtype . kind not in "ifc" :
1168
+ if not _is_continuous ( df , args ["color" ]) :
1165
1169
aggfunc_color = aggfunc_discrete
1166
1170
discrete_color = True
1167
1171
elif not aggfunc_color :
@@ -1227,7 +1231,7 @@ def aggfunc_continuous(x):
1227
1231
return args
1228
1232
1229
1233
1230
- def infer_config (args , constructor , trace_patch ):
1234
+ def infer_config (args , constructor , trace_patch , layout_patch ):
1231
1235
# Declare all supported attributes, across all plot types
1232
1236
attrables = (
1233
1237
["x" , "y" , "z" , "a" , "b" , "c" , "r" , "theta" , "size" , "dimensions" ]
@@ -1263,10 +1267,7 @@ def infer_config(args, constructor, trace_patch):
1263
1267
if "color_discrete_sequence" not in args :
1264
1268
attrs .append ("color" )
1265
1269
else :
1266
- if (
1267
- args ["color" ]
1268
- and args ["data_frame" ][args ["color" ]].dtype .kind in "ifc"
1269
- ):
1270
+ if args ["color" ] and _is_continuous (args ["data_frame" ], args ["color" ]):
1270
1271
attrs .append ("color" )
1271
1272
args ["color_is_continuous" ] = True
1272
1273
elif constructor in [go .Sunburst , go .Treemap ]:
@@ -1305,8 +1306,55 @@ def infer_config(args, constructor, trace_patch):
1305
1306
if "symbol" in args :
1306
1307
grouped_attrs .append ("marker.symbol" )
1307
1308
1308
- # Compute final trace patch
1309
- trace_patch = trace_patch .copy ()
1309
+ if "orientation" in args :
1310
+ has_x = args ["x" ] is not None
1311
+ has_y = args ["y" ] is not None
1312
+ if args ["orientation" ] is None :
1313
+ if constructor in [go .Histogram , go .Scatter ]:
1314
+ if has_y and not has_x :
1315
+ args ["orientation" ] = "h"
1316
+ elif constructor in [go .Violin , go .Box , go .Bar , go .Funnel ]:
1317
+ if has_x and not has_y :
1318
+ args ["orientation" ] = "h"
1319
+
1320
+ if args ["orientation" ] is None and has_x and has_y :
1321
+ x_is_continuous = _is_continuous (args ["data_frame" ], args ["x" ])
1322
+ y_is_continuous = _is_continuous (args ["data_frame" ], args ["y" ])
1323
+ if x_is_continuous and not y_is_continuous :
1324
+ args ["orientation" ] = "h"
1325
+ if y_is_continuous and not x_is_continuous :
1326
+ args ["orientation" ] = "v"
1327
+
1328
+ if args ["orientation" ] is None :
1329
+ args ["orientation" ] = "v"
1330
+
1331
+ if constructor == go .Histogram :
1332
+ if has_x and has_y and args ["histfunc" ] is None :
1333
+ args ["histfunc" ] = trace_patch ["histfunc" ] = "sum"
1334
+
1335
+ orientation = args ["orientation" ]
1336
+ nbins = args ["nbins" ]
1337
+ trace_patch ["nbinsx" ] = nbins if orientation == "v" else None
1338
+ trace_patch ["nbinsy" ] = None if orientation == "v" else nbins
1339
+ trace_patch ["bingroup" ] = "x" if orientation == "v" else "y"
1340
+ trace_patch ["orientation" ] = args ["orientation" ]
1341
+
1342
+ if constructor in [go .Violin , go .Box ]:
1343
+ mode = "boxmode" if constructor == go .Box else "violinmode"
1344
+ if layout_patch [mode ] is None and args ["color" ] is not None :
1345
+ if args ["y" ] == args ["color" ] and args ["orientation" ] == "h" :
1346
+ layout_patch [mode ] = "overlay"
1347
+ elif args ["x" ] == args ["color" ] and args ["orientation" ] == "v" :
1348
+ layout_patch [mode ] = "overlay"
1349
+ if layout_patch [mode ] is None :
1350
+ layout_patch [mode ] = "group"
1351
+
1352
+ if (
1353
+ constructor == go .Histogram2d
1354
+ and args ["z" ] is not None
1355
+ and args ["histfunc" ] is None
1356
+ ):
1357
+ args ["histfunc" ] = trace_patch ["histfunc" ] = "sum"
1310
1358
1311
1359
if constructor in [go .Histogram2d , go .Densitymapbox ]:
1312
1360
show_colorbar = True
@@ -1354,7 +1402,7 @@ def infer_config(args, constructor, trace_patch):
1354
1402
1355
1403
# Create trace specs
1356
1404
trace_specs = make_trace_spec (args , constructor , attrs , trace_patch )
1357
- return args , trace_specs , grouped_mappings , sizeref , show_colorbar
1405
+ return trace_specs , grouped_mappings , sizeref , show_colorbar
1358
1406
1359
1407
1360
1408
def get_orderings (args , grouper , grouped ):
@@ -1398,11 +1446,13 @@ def get_orderings(args, grouper, grouped):
1398
1446
return orders , group_names , group_values
1399
1447
1400
1448
1401
- def make_figure (args , constructor , trace_patch = {}, layout_patch = {}):
1449
+ def make_figure (args , constructor , trace_patch = None , layout_patch = None ):
1450
+ trace_patch = trace_patch or {}
1451
+ layout_patch = layout_patch or {}
1402
1452
apply_default_cascade (args )
1403
1453
1404
- args , trace_specs , grouped_mappings , sizeref , show_colorbar = infer_config (
1405
- args , constructor , trace_patch
1454
+ trace_specs , grouped_mappings , sizeref , show_colorbar = infer_config (
1455
+ args , constructor , trace_patch , layout_patch
1406
1456
)
1407
1457
grouper = [x .grouper or one_group for x in grouped_mappings ] or [one_group ]
1408
1458
grouped = args ["data_frame" ].groupby (grouper , sort = False )
0 commit comments