Data-point callouts
Call out a notable point on a scatter or line chart with explanatory text and an arrow.
Plotly · Module
Adds a standalone text annotation to a Plotly figure, optionally with an arrow. Coordinates can refer to subplot axes, the figure’s paper space, or an axis domain.
Call fig.add_annotation() on a Plotly figure to append one standalone text annotation. Its coordinates default to the plot axes, while xref and yref can switch either coordinate to paper space or an axis domain; arrow and text options control the callout’s appearance.
fig.add_annotation(arg=None, x=None, y=None, xref=None, yref=None, text=None, showarrow=None, arrowhead=None, ax=None, ay=None, **kwargs) domain when positioning relative to an axis’s normalized domain.import plotly.express as px
fig = px.scatter(x=[1, 2, 3], y=[2, 4, 3])
fig.add_annotation(
x=2,
y=4,
text="Peak",
showarrow=True,
arrowhead=2,
)
fig.show()Adds a labeled callout at the data point (2, 4), with an arrow pointing to it.
Call out a notable point on a scatter or line chart with explanatory text and an arrow.
Place a fixed caption, label, or control hint at a precise location in the overall figure.
Annotate values or features in a 2D or 3D Cartesian subplot using the subplot’s coordinate system.
fig.add_annotation() do?It adds a standalone text annotation to an existing figure. The annotation can include an arrow and can use either axis-relative or figure-relative coordinates.
Follow-up: How would you make it stay at a fixed location while panning? Set xref and yref to "paper" and provide paper coordinates.
The default references are xref="x" and yref="y", so x and y are interpreted in the subplot’s data coordinates. This makes the annotation track the plotted data during navigation.
Follow-up: How can placement be relative to an axis domain? Add domain to the relevant axis reference, such as xref="x domain".
Set showarrow=True and configure arrow properties such as arrowhead; provide ax and ay when specifying the arrow’s tail. The arrow dimensions must use the same coordinate system as the arrowhead.
Follow-up: What alternative is available for a simple label without a callout? Set showarrow=False and position the text directly.
fig.update_layoutlayout.annotationslayout.annotation