Skip to content

Commit d9eeca2

Browse files
authored
Merge pull request #1979 from plotly/sankey_hovermode
multiple tooltips
2 parents d59e150 + d595cd5 commit d9eeca2

File tree

5 files changed

+32
-57
lines changed

5 files changed

+32
-57
lines changed

doc/eject.py

-27
This file was deleted.

doc/python/sankey-diagram.md

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fig.show()
9696
```
9797

9898
### Style Sankey Diagram
99+
This example also uses [hovermode](https://plot.ly/python/reference/#layout-hovermode) to enable multiple tooltips.
99100

100101
```python
101102
import plotly.graph_objects as go
@@ -123,6 +124,7 @@ fig = go.Figure(data=[go.Sankey(
123124
))])
124125

125126
fig.update_layout(
127+
hovermode = 'x',
126128
title="Energy forecast for 2050<br>Source: Department of Energy & Climate Change, Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>",
127129
font=dict(size = 10, color = 'white'),
128130
plot_bgcolor='black',

doc/resync.py

-28
This file was deleted.

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)

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)