Skip to content

Commit 2b58eac

Browse files
fix facet labels
1 parent ca464c1 commit 2b58eac

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,9 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
12671267
if m.facet == "row":
12681268
row = m.val_map[val]
12691269
if args["facet_row"] and len(row_labels) < row:
1270-
row_labels.append(args["facet_row"] + "=" + str(val))
1270+
row_labels.append(
1271+
get_label(args, args["facet_row"]) + "=" + str(val)
1272+
)
12711273
else:
12721274
if (
12731275
bool(args.get("marginal_x", False))
@@ -1282,7 +1284,9 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
12821284
if m.facet == "col":
12831285
col = m.val_map[val]
12841286
if args["facet_col"] and len(col_labels) < col:
1285-
col_labels.append(args["facet_col"] + "=" + str(val))
1287+
col_labels.append(
1288+
get_label(args, args["facet_col"]) + "=" + str(val)
1289+
)
12861290
if facet_col_wrap: # assumes no facet_row, no marginals
12871291
row = 1 + ((col - 1) // facet_col_wrap)
12881292
col = 1 + ((col - 1) % facet_col_wrap)

Diff for: packages/python/plotly/plotly/tests/test_core/test_px/test_px.py

+24
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ def test_custom_data_scatter():
5353
)
5454

5555

56+
def test_labels():
57+
tips = px.data.tips()
58+
fig = px.scatter(
59+
tips,
60+
x="total_bill",
61+
y="tip",
62+
facet_row="time",
63+
facet_col="day",
64+
color="size",
65+
symbol="sex",
66+
labels={c: c[::-1] for c in tips.columns},
67+
)
68+
assert "xes" in fig.data[0].hovertemplate
69+
assert "llib_latot" in fig.data[0].hovertemplate
70+
assert "ezis" in fig.data[0].hovertemplate
71+
assert "yad" in fig.data[0].hovertemplate
72+
assert "emit" in fig.data[0].hovertemplate
73+
assert fig.data[0].name.startswith("xes")
74+
assert fig.layout.xaxis.title.text == "llib_latot"
75+
assert fig.layout.coloraxis.colorbar.title.text == "ezis"
76+
assert fig.layout.annotations[0].text.startswith("yad")
77+
assert fig.layout.annotations[4].text.startswith("emit")
78+
79+
5680
def test_px_templates():
5781
import plotly.io as pio
5882
import plotly.graph_objects as go

0 commit comments

Comments
 (0)