Skip to content

Commit d60b4f4

Browse files
initial cut at wide-form support
1 parent d0b8f9f commit d60b4f4

File tree

1 file changed

+18
-2
lines changed
  • packages/python/plotly/plotly/express

1 file changed

+18
-2
lines changed

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def _get_reserved_col_names(args, attrables, array_attrables):
869869
return reserved_names
870870

871871

872-
def build_dataframe(args, attrables, array_attrables):
872+
def build_dataframe(args, attrables, array_attrables, constructor):
873873
"""
874874
Constructs a dataframe and modifies `args` in-place.
875875
@@ -898,6 +898,22 @@ def build_dataframe(args, attrables, array_attrables):
898898
df_provided = args["data_frame"] is not None
899899
if df_provided and not isinstance(args["data_frame"], pd.DataFrame):
900900
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+
901917
df_input = args["data_frame"]
902918

903919
# We start from an empty DataFrame
@@ -1208,7 +1224,7 @@ def infer_config(args, constructor, trace_patch):
12081224
if group_attr in args:
12091225
all_attrables += [group_attr]
12101226

1211-
args = build_dataframe(args, all_attrables, array_attrables)
1227+
args = build_dataframe(args, all_attrables, array_attrables, constructor)
12121228
if constructor in [go.Treemap, go.Sunburst] and args["path"] is not None:
12131229
args = process_dataframe_hierarchy(args)
12141230

0 commit comments

Comments
 (0)