Skip to content

Commit

Permalink
Merge pull request #1966 from plotly/facet_labels
Browse files Browse the repository at this point in the history
fix facet labels
  • Loading branch information
nicolaskruchten authored Dec 4, 2019
2 parents ca464c1 + 2b58eac commit c31802f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions packages/python/plotly/plotly/tests/test_core/test_px/test_px.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c31802f

Please sign in to comment.