diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 1cecba9ba8..849b874f00 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1267,7 +1267,9 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): if m.facet == "row": row = m.val_map[val] if args["facet_row"] and len(row_labels) < row: - row_labels.append(args["facet_row"] + "=" + str(val)) + row_labels.append( + get_label(args, args["facet_row"]) + "=" + str(val) + ) else: if ( bool(args.get("marginal_x", False)) @@ -1282,7 +1284,9 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}): if m.facet == "col": col = m.val_map[val] if args["facet_col"] and len(col_labels) < col: - col_labels.append(args["facet_col"] + "=" + str(val)) + col_labels.append( + get_label(args, args["facet_col"]) + "=" + str(val) + ) if facet_col_wrap: # assumes no facet_row, no marginals row = 1 + ((col - 1) // facet_col_wrap) col = 1 + ((col - 1) % facet_col_wrap) diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py index b644040a5f..736c74461c 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py @@ -53,6 +53,30 @@ def test_custom_data_scatter(): ) +def test_labels(): + tips = px.data.tips() + fig = px.scatter( + tips, + x="total_bill", + y="tip", + facet_row="time", + facet_col="day", + color="size", + symbol="sex", + labels={c: c[::-1] for c in tips.columns}, + ) + assert "xes" in fig.data[0].hovertemplate + assert "llib_latot" in fig.data[0].hovertemplate + assert "ezis" in fig.data[0].hovertemplate + assert "yad" in fig.data[0].hovertemplate + assert "emit" in fig.data[0].hovertemplate + assert fig.data[0].name.startswith("xes") + assert fig.layout.xaxis.title.text == "llib_latot" + assert fig.layout.coloraxis.colorbar.title.text == "ezis" + assert fig.layout.annotations[0].text.startswith("yad") + assert fig.layout.annotations[4].text.startswith("emit") + + def test_px_templates(): import plotly.io as pio import plotly.graph_objects as go