Skip to content

Commit 310db94

Browse files
committed
add hoversubplots examples
1 parent 433ef1b commit 310db94

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed

doc/python/hover-text-and-formatting.md

+35-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.16.1
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.8
23+
version: 3.10.11
2424
plotly:
2525
description: How to use hover text and formatting in Python with Plotly.
2626
display_as: file_settings
@@ -116,6 +116,38 @@ fig.update_layout(hovermode='x unified')
116116
fig.show()
117117
```
118118

119+
#### Hover on Subplots
120+
121+
*New in 5.21*
122+
123+
Use `hoversubplots` to define how hover effects expand to additional subplots. With `hoversubplots=axis`, hover effects are included on stacked subplots using the same axis when `hovermode` is set to `x`, `x unified`, `y`, or `y unified`. In the following example, the three stacked scatter plots use the same `xaxis`:
124+
125+
```python
126+
import plotly.graph_objects as go
127+
import pandas as pd
128+
from plotly import data
129+
130+
df = data.stocks()
131+
132+
date_range = pd.date_range(start="1/1/2020", end="1/10/2020")
133+
134+
layout = dict(
135+
hoversubplots="axis",
136+
title="Stock Price Changes",
137+
hovermode="x",
138+
grid=dict(rows=3, columns=1),
139+
)
140+
141+
data = [
142+
go.Scatter(x=df["date"], y=df["AAPL"], xaxis="x", yaxis="y", name="Apple"),
143+
go.Scatter(x=df["date"], y=df["GOOG"], xaxis="x", yaxis="y2", name="Google"),
144+
go.Scatter(x=df["date"], y=df["AMZN"], xaxis="x", yaxis="y3", name="Amazon"),
145+
]
146+
147+
fig = go.Figure(data=data, layout=layout)
148+
fig.show()
149+
```
150+
119151
### Customizing Hover Label Appearance
120152

121153
Hover label text and colors default to trace colors in hover modes other than `unified`, and can be globally set via the `layout.hoverlabel` attributes. Hover label appearance can also be controlled per trace in `<trace>.hoverlabel`.

doc/python/splom.md

+54-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.1'
9-
jupytext_version: 1.1.1
8+
format_version: '1.3'
9+
jupytext_version: 1.16.1
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.7
23+
version: 3.10.11
2424
plotly:
2525
description: How to make scatterplot matrices or sploms natively in Python with
2626
Plotly.
@@ -77,7 +77,6 @@ fig.update_traces(diagonal_visible=False)
7777
fig.show()
7878
```
7979

80-
<!-- #region -->
8180

8281
### Scatter matrix (splom) with go.Splom
8382

@@ -103,7 +102,7 @@ trace=go.Splom(dimensions=[dict(label='string-1',
103102

104103
The label in each dimension is assigned to the axes titles of the corresponding matrix cell.
105104

106-
<!-- #endregion -->
105+
107106

108107
#### Splom of the Iris data set
109108

@@ -290,6 +289,55 @@ fig.update_layout(title=title,
290289

291290
fig.show()
292291
```
292+
#### Hover Effects
293+
294+
*New in 5.21*
295+
296+
Set `hoversubplots='axis'` with `hovermode` set to `x`, `x unified`, `y`, or `y unified` for hover effects to appear across a column or row.
297+
298+
For more on hover effects see the [Hover Text and Formatting](/python/hover-text-and-formatting/) page.
299+
300+
```python
301+
import plotly.graph_objects as go
302+
import pandas as pd
303+
304+
df = pd.read_csv(
305+
"https://raw.githubusercontent.com/plotly/datasets/master/iris-data.csv"
306+
)
307+
index_vals = df["class"].astype("category").cat.codes
308+
309+
fig = go.Figure(
310+
data=go.Splom(
311+
dimensions=[
312+
dict(label="sepal length", values=df["sepal length"]),
313+
dict(label="sepal width", values=df["sepal width"]),
314+
dict(label="petal length", values=df["petal length"]),
315+
dict(label="petal width", values=df["petal width"]),
316+
],
317+
showupperhalf=False,
318+
text=df["class"],
319+
marker=dict(
320+
color=index_vals,
321+
showscale=False,
322+
line_color="white",
323+
line_width=0.5,
324+
),
325+
)
326+
)
327+
328+
329+
fig.update_layout(
330+
title="Iris Data set",
331+
hoversubplots="axis",
332+
width=600,
333+
height=600,
334+
hovermode="x",
335+
)
336+
337+
fig.show()
338+
339+
```
340+
293341
#### Reference
294342

295343
See [function reference for `px.scatter_matrix()`](https://plotly.com/python-api-reference/generated/plotly.express.scatter_matrix) or https://plotly.com/python/reference/splom/ for more information and chart attribute options!

0 commit comments

Comments
 (0)