|
5 | 5 | text_representation:
|
6 | 6 | extension: .md
|
7 | 7 | format_name: markdown
|
8 |
| - format_version: '1.1' |
9 |
| - jupytext_version: 1.2.1 |
| 8 | + format_version: '1.2' |
| 9 | + jupytext_version: 1.3.0 |
10 | 10 | kernelspec:
|
11 | 11 | display_name: Python 3
|
12 | 12 | language: python
|
@@ -201,6 +201,34 @@ fig.update_layout(
|
201 | 201 | fig.show()
|
202 | 202 | ```
|
203 | 203 |
|
| 204 | +### Adding other data to the hover with customdata and a hovertemplate |
| 205 | + |
| 206 | +`go` traces have a `customdata` argument in which you can add an array, which outer dimensions should have the same dimensions as the plotted data. You can then use `customdata` inside a `hovertemplate` to display the value of customdata. |
| 207 | + |
| 208 | +```python |
| 209 | +import plotly.graph_objects as go |
| 210 | +from plotly.subplots import make_subplots |
| 211 | +import numpy as np |
| 212 | +np.random.seed(0) |
| 213 | +z1, z2, z3 = np.random.random((3, 7, 7)) |
| 214 | +customdata = np.dstack((z2, z3)) |
| 215 | +fig = make_subplots(1, 2, subplot_titles=['z1', 'z2']) |
| 216 | +fig.add_trace(go.Heatmap( |
| 217 | + z=z1, |
| 218 | + customdata=np.dstack((z2, z3)), |
| 219 | + hovertemplate='<b>z1:%{z:.3f}</b><br>z2:%{customdata[0]:.3f} <br>z3: %{customdata[1]:.3f} ', |
| 220 | + coloraxis="coloraxis1", name=''), |
| 221 | + 1, 1) |
| 222 | +fig.add_trace(go.Heatmap( |
| 223 | + z=z2, |
| 224 | + customdata=np.dstack((z1, z3)), |
| 225 | + hovertemplate='z1:%{customdata[0]:.3f} <br><b>z2:%{z:.3f}</b><br>z3: %{customdata[1]:.3f} ', |
| 226 | + coloraxis="coloraxis1", name=''), |
| 227 | + 1, 2) |
| 228 | +fig.update_layout(title_text='Hover to see the value of z1, z2 and z3 together') |
| 229 | +fig.show() |
| 230 | +``` |
| 231 | + |
204 | 232 | ### Set Hover Template in Mapbox
|
205 | 233 | ```python
|
206 | 234 | import plotly.graph_objects as go
|
|
0 commit comments