Skip to content

Commit f2a0079

Browse files
wip
1 parent 9d45dc8 commit f2a0079

File tree

1 file changed

+15
-11
lines changed
  • packages/python/plotly/plotly/express

1 file changed

+15
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Declare all supported attributes, across all plot types
2020
direct_attrables = (
2121
["x", "y", "z", "a", "b", "c", "r", "theta", "size"]
22-
+ ["hover_name", "text", "names", "values", "parents"]
22+
+ ["hover_name", "text", "names", "values", "parents", "wide_cross"]
2323
+ ["ids", "error_x", "error_x_minus", "error_y", "error_y_minus", "error_z"]
2424
+ ["error_z_minus", "lat", "lon", "locations", "animation_group"]
2525
)
@@ -952,10 +952,11 @@ def build_dataframe(args, constructor):
952952

953953
if wide_mode:
954954
# currently assuming that df_provided == True
955-
args["wide_cols"] = [df_input.index] + list(df_input.columns)
955+
args["wide_cols"] = list(df_input.columns)
956+
args["wide_cross"] = df_input.index
956957
var_name = df_input.columns.name or "_column_"
957-
index_name = df_input.index.name or "index"
958-
wide_id_vars.add(index_name)
958+
wide_orientation = args.get("orientation", None) or "v"
959+
args["orientation"] = wide_orientation
959960

960961
"""
961962
wide_x detection
@@ -973,10 +974,11 @@ def build_dataframe(args, constructor):
973974
- else = long mode
974975
975976
so what we want is:
976-
- y = [col col] -> melt just those
977-
- x = [col col] -> melt just those but swap the orientation? except in hist mode
978-
- y = [col col] / x=col -> melt just those and force x to not be the index ... what about hist
977+
- y = [col col] -> melt just those, wide_orientation = 'v'/no override, cross_dim = index or range
978+
- y = [col col] / x=col -> wide_orientation = 'h'/no override, cross_dim = x
979979
- y = [col col] / x=[col col] -> error
980+
981+
need to merge wide logic into no_x/no_y logic below for range() etc
980982
"""
981983

982984
df_output = pd.DataFrame()
@@ -1161,22 +1163,24 @@ def build_dataframe(args, constructor):
11611163
if wide_mode:
11621164
wide_value_vars = [c for c in args["wide_cols"] if c not in wide_id_vars]
11631165
del args["wide_cols"]
1166+
wide_cross = args["wide_cross"]
1167+
del args["wide_cross"]
11641168
df_output = df_output.melt(
11651169
id_vars=wide_id_vars,
11661170
value_vars=wide_value_vars,
11671171
var_name=var_name,
11681172
value_name="_value_",
11691173
)
11701174
df_output[var_name] = df_output[var_name].astype(str)
1171-
args["orientation"] = args.get("orientation", None) or "v"
1172-
orient_v = args["orientation"] == "v"
1175+
orient_v = wide_orientation == "v"
1176+
11731177
if constructor == go.Scatter:
1174-
args["x" if orient_v else "y"] = index_name
1178+
args["x" if orient_v else "y"] = wide_cross
11751179
args["y" if orient_v else "x"] = "_value_"
11761180
args["color"] = args["color"] or var_name
11771181
if constructor == go.Bar:
11781182
if _is_continuous(df_output, "_value_"):
1179-
args["x" if orient_v else "y"] = index_name
1183+
args["x" if orient_v else "y"] = wide_cross
11801184
args["y" if orient_v else "x"] = "_value_"
11811185
args["color"] = args["color"] or var_name
11821186
else:

0 commit comments

Comments
 (0)