@@ -869,7 +869,7 @@ def _get_reserved_col_names(args, attrables, array_attrables):
869
869
return reserved_names
870
870
871
871
872
- def build_dataframe (args , attrables , array_attrables ):
872
+ def build_dataframe (args , attrables , array_attrables , constructor ):
873
873
"""
874
874
Constructs a dataframe and modifies `args` in-place.
875
875
@@ -898,6 +898,22 @@ def build_dataframe(args, attrables, array_attrables):
898
898
df_provided = args ["data_frame" ] is not None
899
899
if df_provided and not isinstance (args ["data_frame" ], pd .DataFrame ):
900
900
args ["data_frame" ] = pd .DataFrame (args ["data_frame" ])
901
+
902
+ if not args .get ("x" , None ) and not args .get ("y" , None ) and df_provided :
903
+ if constructor in [go .Scatter , go .Bar ]:
904
+ args ["data_frame" ] = args ["data_frame" ].reset_index ().melt (id_vars = "index" )
905
+ args ["x" ] = "index"
906
+ args ["y" ] = "value"
907
+ args ["color" ] = "variable"
908
+ if constructor in [go .Violin , go .Box ]:
909
+ args ["data_frame" ] = args ["data_frame" ].reset_index ().melt (id_vars = "index" )
910
+ args ["x" ] = "variable"
911
+ args ["y" ] = "value"
912
+ if constructor in [go .Histogram ]:
913
+ args ["data_frame" ] = args ["data_frame" ].reset_index ().melt (id_vars = "index" )
914
+ args ["x" ] = "value"
915
+ args ["color" ] = "variable"
916
+
901
917
df_input = args ["data_frame" ]
902
918
903
919
# We start from an empty DataFrame
@@ -1208,7 +1224,7 @@ def infer_config(args, constructor, trace_patch):
1208
1224
if group_attr in args :
1209
1225
all_attrables += [group_attr ]
1210
1226
1211
- args = build_dataframe (args , all_attrables , array_attrables )
1227
+ args = build_dataframe (args , all_attrables , array_attrables , constructor )
1212
1228
if constructor in [go .Treemap , go .Sunburst ] and args ["path" ] is not None :
1213
1229
args = process_dataframe_hierarchy (args )
1214
1230
0 commit comments