Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
nicolaskruchten committed Jan 9, 2020
commit b57def20a84f20419c7a905876c72c17c89b335d
12 changes: 8 additions & 4 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,20 +1184,22 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
nrows = ncols = 1
col_labels = []
row_labels = []
trace_name_labels = []
for group_name in sorted_group_names:
group = grouped.get_group(group_name if len(group_name) > 1 else group_name[0])
mapping_labels = OrderedDict()
trace_name_labels = OrderedDict()
frame_name = ""
trace_name = []
for col, val, m in zip(grouper, group_name, grouped_mappings):
if col != one_group:
key = get_label(args, col)
mapping_labels[key] = str(val)
if m.show_in_trace_name:
trace_name_labels[key] = str(val)
trace_name_labels.append(key)
trace_name.append(str(val))
if m.variable == "animation_frame":
frame_name = val
trace_name = ", ".join(trace_name_labels.values())
trace_name = ", ".join(trace_name)
if frame_name not in trace_names_by_frame:
trace_names_by_frame[frame_name] = set()
trace_names = trace_names_by_frame[frame_name]
Expand Down Expand Up @@ -1346,7 +1348,9 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
for v in ["title", "height", "width"]:
if args[v]:
layout_patch[v] = args[v]
layout_patch["legend"] = dict(tracegroupgap=0, title=", ".join(trace_name_labels))
layout_patch["legend"] = dict(tracegroupgap=0)
if trace_name_labels:
layout_patch["legend"]["title"] = ", ".join(trace_name_labels)
if "title" not in layout_patch and args["template"].layout.margin.t is None:
layout_patch["margin"] = {"t": 60}
if (
Expand Down
22 changes: 11 additions & 11 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 @@ -63,18 +63,18 @@ def test_labels():
facet_col="day",
color="size",
symbol="sex",
labels={c: c[::-1] for c in tips.columns},
labels={c: c.upper() 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")
assert "SEX" in fig.data[0].hovertemplate
assert "TOTAL_BILL" in fig.data[0].hovertemplate
assert "SIZE" in fig.data[0].hovertemplate
assert "DAY" in fig.data[0].hovertemplate
assert "TIME" in fig.data[0].hovertemplate
assert fig.layout.legend.title.text.startswith("SEX")
assert fig.layout.xaxis.title.text == "TOTAL_BILL"
assert fig.layout.coloraxis.colorbar.title.text == "SIZE"
assert fig.layout.annotations[0].text.startswith("DAY")
assert fig.layout.annotations[4].text.startswith("TIME")


def test_px_templates():
Expand Down