Dash Plotly Line Chart: Customize Hover Information with `hovertemplate`
Dash Plotly Line Chart: Customize Hover Information with hovertemplate
In Dash Plotly line charts, you can control the information displayed when hovering over data points using HTML markup within the hovertemplate attribute. This allows for customized formatting and the exclusion of specific values.
Example: Restricting the hover information to only the y-value with two decimal places.
import plotly.graph_objs as go
x = [1, 2, 3, 4, 5]
y = [1.234567, 2.345678, 3.456789, 4.567890, 5.678901]
trace = go.Scatter(x=x, y=y, mode='lines+markers', hovertemplate='y=%{y:.2f}<extra></extra>')
layout = go.Layout(hovermode='x')
fig = go.Figure(data=[trace], layout=layout)
fig.show()
In this example, hovertemplate is set to 'y=%{y:.2f}<extra></extra>'. %{y:.2f} formats the y-value to display only two decimal places. The <extra></extra> tag ensures that no other information is displayed when hovering.
By using hovertemplate, you can create customized and concise hover information that effectively presents your data.
原文地址: https://www.cveoy.top/t/topic/nicB 著作权归作者所有。请勿转载和采集!