Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2e26e8

Browse files
committed
small edits in hovermode tutorial
1 parent b2c463b commit f2e26e8

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.3.1
9+
jupytext_version: 1.3.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.8
23+
version: 3.7.3
2424
plotly:
2525
description: How to use hover text and formatting in Python with Plotly.
2626
display_as: file_settings
@@ -34,9 +34,11 @@ jupyter:
3434

3535
### Hover Labels
3636

37-
One of the most deceptively-power features of interactive visualization using Plotly is the ability for the user to reveal more information about a data point by moving their mouse cursort over the point and having a hover label appear.
37+
One of the most deceptively-power features of interactive visualization using Plotly is the ability for the user to reveal more information about a data point by moving their mouse cursor over the point and having a hover label appear.
3838

39-
There are three hover modes available in Plotly. The default setting is `layout.hovermode='closest'`, wherein a single hover label appears for the point directly underneat the cursor:
39+
There are three hover modes available in Plotly. The default setting is `layout.hovermode='closest'`, wherein a single hover label appears for the point directly underneath the cursor.
40+
41+
#### Hovermode `closest` (default mode)
4042

4143
```python
4244
import plotly.express as px
@@ -49,6 +51,8 @@ fig.update_traces(mode="markers+lines")
4951
fig.show()
5052
```
5153

54+
#### Hovermode `x` or `y`
55+
5256
If `layout.hovermode='x'` (or `'y'`), a single hover label appears per trace, for points at the same `x` (or `y`) value as the cursor. If multiple points in a given trace exist at the same coordinate, only one will get a hover label. In the line plot below we have forced markers to appear, to make it clearer what can be hovered over, and we have disabled the built-in Plotly Express `hovertemplate` by setting it to `None`, resulting in a more compact hover label per point:
5357

5458
```python
@@ -63,6 +67,8 @@ fig.update_layout(hovermode="x")
6367
fig.show()
6468
```
6569

70+
#### Unified hovermode
71+
6672
If `layout.hovermode='x unified'` (or `'y unified'`), a single hover label appear, describing one point per trace, for points at the same `x` (or `y`) value as the cursor. If multiple points in a given trace exist at the same coordinate, only one will get an entry in the hover label. In the line plot below we have forced markers to appear, to make it clearer what can be hovered over, and we have disabled the built-in Plotly Express `hovertemplate` by setting it to `None`, resulting in a more compact entry per point in the hover label:
6773

6874
```python
@@ -77,6 +83,21 @@ fig.update_layout(hovermode="x unified")
7783
fig.show()
7884
```
7985

86+
#### Selecting a hovermode in a figure created with `plotly.graph_objects`
87+
88+
The hovermode is a property of the figure layout, so you can select a hovermode no matter how you created the figure, either with `plotly.express` or with `plotly.graph_objects`. Below is an example with a figure created with `plotly.graph_objects`. If you're not familiar with the structure of plotly figures, you can read [the tutorial on creating and updating plotly figures](/python/creating-and-updating-figures/).
89+
90+
```python
91+
import plotly.graph_objects as go
92+
import numpy as np
93+
t = np.linspace(0, 2 * np.pi, 100)
94+
fig = go.Figure()
95+
fig.add_trace(go.Scatter(x=t, y=np.sin(t), name='sin(t)'))
96+
fig.add_trace(go.Scatter(x=t, y=np.cos(t), name='cost(t)'))
97+
fig.update_layout(hovermode='x unified')
98+
fig.show()
99+
```
100+
80101
### Customizing Hover Label Appearance
81102

82103
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/time-series.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fig = px.scatter(df, x='Date', y='AAPL.High', range_x=['2015-12-01', '2016-01-15
204204
fig.update_xaxes(
205205
rangebreaks=[
206206
dict(bounds=["sat", "mon"]), #hide weekends
207-
dict(values=["2015-12-25", "2016-01-01"]) #hide Christmas and New Year's
207+
dict(values=["2015-12-25", "2016-01-01"]) # hide Christmas and New Year's
208208
]
209209
)
210210
fig.show()

0 commit comments

Comments
 (0)