Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix facet labels #1966

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not :-)

)
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