Skip to content

Commit 39f7856

Browse files
mostly finished ECDF
1 parent afe8083 commit 39f7856

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ def ecdf(
476476
x=None,
477477
y=None,
478478
color=None,
479+
text=None,
479480
line_dash=None,
480481
facet_row=None,
481482
facet_col=None,
@@ -495,9 +496,9 @@ def ecdf(
495496
marginal=None,
496497
opacity=None,
497498
orientation=None,
498-
line_shape=None,
499-
norm=None, # TODO use this
500-
complementary=None, # TODO use this
499+
line_shape="hv",
500+
norm="probability",
501+
complementary=False,
501502
log_x=False,
502503
log_y=False,
503504
range_x=None,

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

+37-10
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,17 @@ def get_decorated_label(args, column, role):
153153
or (role == "x" and "orientation" in args and args["orientation"] == "h")
154154
or (role == "y" and "orientation" in args and args["orientation"] == "v")
155155
):
156-
if label:
157-
label = "%s of %s" % (args["histfunc"] or "count", label)
156+
histfunc = args["histfunc"] or "count"
157+
if label and histfunc != "count":
158+
label = "%s of %s" % (histfunc, label)
158159
else:
159160
label = "count"
160161

161162
if "histnorm" in args and args["histnorm"] is not None:
162-
label = "%s of %s" % (args["histnorm"], label)
163+
if label == "count":
164+
label = args["histnorm"]
165+
else:
166+
label = "%s of %s" % (args["histnorm"], label)
163167

164168
if "barnorm" in args and args["barnorm"] is not None:
165169
label = "%s (normalized as %s)" % (label, args["barnorm"])
@@ -1421,11 +1425,7 @@ def build_dataframe(args, constructor):
14211425

14221426
if hist1d_orientation:
14231427
args["x" if orient_v else "y"] = value_name
1424-
if wide_cross_name is None and constructor == go.Scatter:
1425-
args["y" if orient_v else "x"] = count_name
1426-
df_output[count_name] = 1
1427-
else:
1428-
args["y" if orient_v else "x"] = wide_cross_name
1428+
args["y" if orient_v else "x"] = wide_cross_name
14291429
args["color"] = args["color"] or var_name
14301430
elif constructor in [go.Scatter, go.Funnel] + hist2d_types:
14311431
args["x" if orient_v else "y"] = wide_cross_name
@@ -1447,6 +1447,21 @@ def build_dataframe(args, constructor):
14471447
elif constructor in [go.Violin, go.Box]:
14481448
args["x" if orient_v else "y"] = wide_cross_name or var_name
14491449
args["y" if orient_v else "x"] = value_name
1450+
1451+
if hist1d_orientation and constructor == go.Scatter:
1452+
if args["x"] is not None and args["y"] is not None:
1453+
args["histfunc"] = "sum"
1454+
elif args["x"] is None:
1455+
args["histfunc"] = None
1456+
args["orientation"] = "h"
1457+
args["x"] = count_name
1458+
df_output[count_name] = 1
1459+
else:
1460+
args["histfunc"] = None
1461+
args["orientation"] = "v"
1462+
args["y"] = count_name
1463+
df_output[count_name] = 1
1464+
14501465
if no_color:
14511466
args["color"] = None
14521467
args["data_frame"] = df_output
@@ -1743,8 +1758,10 @@ def infer_config(args, constructor, trace_patch, layout_patch):
17431758
trace_patch["opacity"] = args["opacity"]
17441759
else:
17451760
trace_patch["marker"] = dict(opacity=args["opacity"])
1746-
if "line_group" in args:
1747-
trace_patch["mode"] = "lines" + ("+markers+text" if args["text"] else "")
1761+
if "line_group" in args or "line_dash" in args:
1762+
trace_patch["mode"] = "lines" + (
1763+
"+markers+text" if args.get("text", None) is not None else ""
1764+
)
17481765
elif constructor != go.Splom and (
17491766
"symbol" in args or constructor == go.Scattermapbox
17501767
):
@@ -2001,7 +2018,17 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
20012018
base = args["x"] if args["orientation"] == "v" else args["y"]
20022019
var = args["x"] if args["orientation"] == "h" else args["y"]
20032020
group = group.sort_values(by=base)
2021+
group_sum = group[var].sum()
20042022
group[var] = group[var].cumsum()
2023+
if args["complementary"]:
2024+
group[var] = group_sum - group[var]
2025+
2026+
if args["norm"] == "probability":
2027+
group[var] = group[var] / group_sum
2028+
elif args["norm"] == "percent":
2029+
group[var] = 100.0 * group[var] / group_sum
2030+
args["histnorm"] = args["norm"]
2031+
# TODO norm, including histnorm-like naming
20052032

20062033
patch, fit_results = make_trace_kwargs(
20072034
args, trace_spec, group, mapping_labels.copy(), sizeref

0 commit comments

Comments
 (0)