Skip to content

Commit 538f18e

Browse files
mostly finished ECDF
1 parent 700e83f commit 538f18e

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

packages/python/plotly/plotly/express/_chart_types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ def ecdf(
494494
x=None,
495495
y=None,
496496
color=None,
497+
text=None,
497498
line_dash=None,
498499
facet_row=None,
499500
facet_col=None,
@@ -513,9 +514,9 @@ def ecdf(
513514
marginal=None,
514515
opacity=None,
515516
orientation=None,
516-
line_shape=None,
517-
norm=None, # TODO use this
518-
complementary=None, # TODO use this
517+
line_shape="hv",
518+
norm="probability",
519+
complementary=False,
519520
log_x=False,
520521
log_y=False,
521522
range_x=None,

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,11 +1465,7 @@ def build_dataframe(args, constructor):
14651465

14661466
if hist1d_orientation:
14671467
args["x" if orient_v else "y"] = value_name
1468-
if wide_cross_name is None and constructor == go.Scatter:
1469-
args["y" if orient_v else "x"] = count_name
1470-
df_output[count_name] = 1
1471-
else:
1472-
args["y" if orient_v else "x"] = wide_cross_name
1468+
args["y" if orient_v else "x"] = wide_cross_name
14731469
args["color"] = args["color"] or var_name
14741470
elif constructor in [go.Scatter, go.Funnel] + hist2d_types:
14751471
args["x" if orient_v else "y"] = wide_cross_name
@@ -1491,6 +1487,21 @@ def build_dataframe(args, constructor):
14911487
elif constructor in [go.Violin, go.Box]:
14921488
args["x" if orient_v else "y"] = wide_cross_name or var_name
14931489
args["y" if orient_v else "x"] = value_name
1490+
1491+
if hist1d_orientation and constructor == go.Scatter:
1492+
if args["x"] is not None and args["y"] is not None:
1493+
args["histfunc"] = "sum"
1494+
elif args["x"] is None:
1495+
args["histfunc"] = None
1496+
args["orientation"] = "h"
1497+
args["x"] = count_name
1498+
df_output[count_name] = 1
1499+
else:
1500+
args["histfunc"] = None
1501+
args["orientation"] = "v"
1502+
args["y"] = count_name
1503+
df_output[count_name] = 1
1504+
14941505
if no_color:
14951506
args["color"] = None
14961507
args["data_frame"] = df_output
@@ -1788,7 +1799,9 @@ def infer_config(args, constructor, trace_patch, layout_patch):
17881799
trace_patch["opacity"] = args["opacity"]
17891800
else:
17901801
trace_patch["marker"] = dict(opacity=args["opacity"])
1791-
if "line_group" in args: # px.line, px.line_*, px.area
1802+
if (
1803+
"line_group" in args or "line_dash" in args
1804+
): # px.line, px.line_*, px.area, px.ecdf, px, kde
17921805
modes = set(["lines"])
17931806
if args.get("text") or args.get("symbol") or args.get("markers"):
17941807
modes.add("markers")
@@ -2061,7 +2074,17 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
20612074
base = args["x"] if args["orientation"] == "v" else args["y"]
20622075
var = args["x"] if args["orientation"] == "h" else args["y"]
20632076
group = group.sort_values(by=base)
2077+
group_sum = group[var].sum()
20642078
group[var] = group[var].cumsum()
2079+
if args["complementary"]:
2080+
group[var] = group_sum - group[var]
2081+
2082+
if args["norm"] == "probability":
2083+
group[var] = group[var] / group_sum
2084+
elif args["norm"] == "percent":
2085+
group[var] = 100.0 * group[var] / group_sum
2086+
args["histnorm"] = args["norm"]
2087+
# TODO norm, including histnorm-like naming
20652088

20662089
patch, fit_results = make_trace_kwargs(
20672090
args, trace_spec, group, mapping_labels.copy(), sizeref

0 commit comments

Comments
 (0)