Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 9c005fb

Browse files
hover and axis indication of histfunc
1 parent 1ba02e8 commit 9c005fb

File tree

3 files changed

+2330
-2245
lines changed

3 files changed

+2330
-2245
lines changed

Diff for: gallery.ipynb

+2,308-2,240
Large diffs are not rendered by default.

Diff for: plotly_express/_chart_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def histogram(
226226
trace_patch=dict(
227227
orientation=orientation,
228228
histnorm=normalization,
229-
histfunc="sum" if histfunc is None and x and y else histfunc,
229+
histfunc=histfunc,
230230
nbinsx=nbins if orientation == "v" else None,
231231
nbinsy=nbins if orientation == "h" else None,
232232
cumulative=dict(enabled=cumulative),

Diff for: plotly_express/_core.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ def get_label(args, column):
5252
return column
5353

5454

55+
def get_decorated_label(args, column, role):
56+
label = get_label(args, column)
57+
if "histfunc" in args and (
58+
(role == "x" and args["orientation"] == "h")
59+
or (role == "y" and args["orientation"] == "v")
60+
):
61+
if label:
62+
return "%s of %s" % (args["histfunc"] or "count", label)
63+
else:
64+
return "count"
65+
else:
66+
return label
67+
68+
5569
def make_mapping(args, variable):
5670
if variable == "line_group" or variable == "animation_frame":
5771
return Mapping(
@@ -98,7 +112,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref, color_range)
98112
hover_header = ""
99113
for k in trace_spec.attrs:
100114
v = args[k]
101-
v_label = get_label(args, v)
115+
v_label = get_decorated_label(args, v, k)
102116
if k == "dimensions":
103117
result["dimensions"] = [
104118
dict(
@@ -119,7 +133,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref, color_range)
119133
or len(args["data_frame"][name].unique()) <= 20
120134
)
121135
]
122-
elif v:
136+
elif v or (trace_spec.constructor == go.Histogram and k in ["x", "y"]):
123137
if k == "size":
124138
if "marker" not in result:
125139
result["marker"] = dict()
@@ -209,7 +223,8 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref, color_range)
209223
result[k] = g[v]
210224
mapping_labels.append(("%s=%%{%s}" % (v_label, "location"), None))
211225
else:
212-
result[k] = g[v]
226+
if v:
227+
result[k] = g[v]
213228
mapping_labels.append(("%s=%%{%s}" % (v_label, k), None))
214229
if trace_spec.constructor not in [
215230
go.Box,
@@ -315,7 +330,9 @@ def configure_cartesian_axes(args, fig, axes, orders):
315330
layout["grid"][letter + "axes"].append(letter_number)
316331
axis = letter_number.replace(letter, letter + "axis")
317332

318-
layout[axis] = dict(title=get_label(args, args[letter]))
333+
layout[axis] = dict(
334+
title=get_decorated_label(args, args[letter], letter)
335+
)
319336
if len(letter_number) == 1:
320337
set_cartesian_axis_opts(args, layout, letter, axis, orders)
321338
else:

0 commit comments

Comments
 (0)