Skip to content

Commit b666924

Browse files
mostly finished ECDF
1 parent 7d1e663 commit b666924

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
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

+30-7
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,7 @@ def build_dataframe(args, constructor):
14381438

14391439
if hist1d_orientation:
14401440
args["x" if orient_v else "y"] = value_name
1441-
if wide_cross_name is None and constructor == go.Scatter:
1442-
args["y" if orient_v else "x"] = count_name
1443-
df_output[count_name] = 1
1444-
else:
1445-
args["y" if orient_v else "x"] = wide_cross_name
1441+
args["y" if orient_v else "x"] = wide_cross_name
14461442
args["color"] = args["color"] or var_name
14471443
elif constructor in [go.Scatter, go.Funnel] + hist2d_types:
14481444
args["x" if orient_v else "y"] = wide_cross_name
@@ -1464,6 +1460,21 @@ def build_dataframe(args, constructor):
14641460
elif constructor in [go.Violin, go.Box]:
14651461
args["x" if orient_v else "y"] = wide_cross_name or var_name
14661462
args["y" if orient_v else "x"] = value_name
1463+
1464+
if hist1d_orientation and constructor == go.Scatter:
1465+
if args["x"] is not None and args["y"] is not None:
1466+
args["histfunc"] = "sum"
1467+
elif args["x"] is None:
1468+
args["histfunc"] = None
1469+
args["orientation"] = "h"
1470+
args["x"] = count_name
1471+
df_output[count_name] = 1
1472+
else:
1473+
args["histfunc"] = None
1474+
args["orientation"] = "v"
1475+
args["y"] = count_name
1476+
df_output[count_name] = 1
1477+
14671478
if no_color:
14681479
args["color"] = None
14691480
args["data_frame"] = df_output
@@ -1760,8 +1771,10 @@ def infer_config(args, constructor, trace_patch, layout_patch):
17601771
trace_patch["opacity"] = args["opacity"]
17611772
else:
17621773
trace_patch["marker"] = dict(opacity=args["opacity"])
1763-
if "line_group" in args:
1764-
trace_patch["mode"] = "lines" + ("+markers+text" if args["text"] else "")
1774+
if "line_group" in args or "line_dash" in args:
1775+
trace_patch["mode"] = "lines" + (
1776+
"+markers+text" if args.get("text", None) is not None else ""
1777+
)
17651778
elif constructor != go.Splom and (
17661779
"symbol" in args or constructor == go.Scattermapbox
17671780
):
@@ -2018,7 +2031,17 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
20182031
base = args["x"] if args["orientation"] == "v" else args["y"]
20192032
var = args["x"] if args["orientation"] == "h" else args["y"]
20202033
group = group.sort_values(by=base)
2034+
group_sum = group[var].sum()
20212035
group[var] = group[var].cumsum()
2036+
if args["complementary"]:
2037+
group[var] = group_sum - group[var]
2038+
2039+
if args["norm"] == "probability":
2040+
group[var] = group[var] / group_sum
2041+
elif args["norm"] == "percent":
2042+
group[var] = 100.0 * group[var] / group_sum
2043+
args["histnorm"] = args["norm"]
2044+
# TODO norm, including histnorm-like naming
20222045

20232046
patch, fit_results = make_trace_kwargs(
20242047
args, trace_spec, group, mapping_labels.copy(), sizeref

0 commit comments

Comments
 (0)