jupyter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Many plotly express functions support configurable hover text. The hover_data
argument accepts a list of column names to be added to the hover tooltip. The hover_name
property controls which column is displayed in bold as the tooltip title.
Here is an example that creates a scatter plot using plotly express with custom hover data and a custom hover name.
import plotly.express as px
gapminder_2007 = px.data.gapminder().query("year==2007")
fig = px.scatter(gapminder_2007, x="gdpPercap", y="lifeExp", log_x=True,
hover_name="country", hover_data=["continent"])
fig.show()
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[1, 2, 3, 4, 5],
y=[2, 1, 6, 4, 4],
hovertext=["Text A", "Text B", "Text C", "Text D", "Text E"],
hoverinfo="text",
marker=dict(
color="green"
),
showlegend=False
))
fig.show()
import plotly.graph_objects as go
fig = go.Figure(go.Scatter(
x=[1, 2, 3, 4, 5],
y=[2.02825, 1.63728, 6.83839, 4.8485, 4.73463],
hoverinfo="y",
marker=dict(
color="green"
),
showlegend=False
))
fig.update_layout(
title_text=("Set hover text formatting<br>" +
"<a href= https://github.com/d3/d3-time-format/blob/master/README.md#locale_format>" +
"https://github.com/d3/d3-time-format/blob/master/README.md#locale_format</a>"),
title_font=dict(
size=10
),
)
fig.update_xaxes(zeroline=False)
fig.update_yaxes(hoverformat=".2f")
fig.show()
See https://plot.ly/python/reference/ for more information and chart attribute options!