You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following snippet should produce a figure where the annotation is parallel to the line, however if the figure size changes the rotation of the annotation doesn't change.
importplotly.graph_objectsasgoimportmath# Create a figurefig=go.Figure()
# Add some sample datafig.add_trace(go.Scatter(x=[1, 2, 3, 4, 5], y=[10, 12, 15, 17, 20], mode="lines", name="Data"))
# Define the start and end points of the diagonal linex0, y0=1, 11# Start pointx1, y1=5, 19# End point# Calculate the angle for the annotation textangle=math.degrees(math.atan2((y1-y0), (x1-x0)))
# Add a diagonal line using add_shapefig.add_shape(
type="line",
x0=x0,
y0=y0,
x1=x1,
y1=y1,
line=dict(color="Green", width=2, dash="dash"),
)
# Calculate the midpoint positionmid_x= (x0+x1) /2mid_y= (y0+y1) /2# Annotate the line with rotated textfig.add_annotation(
x=mid_x, # Midpoint of the line for annotation positiony=mid_y,
text="Diagonal Line",
showarrow=False,
textangle=angle, # Rotate text to match line anglefont=dict(color="Green"),
xshift=10, # Optional: Adjust this to fine-tune horizontal alignmentyshift=-10# Optional: Adjust this to fine-tune vertical alignment
)
fig.update_layout(title="Diagonal Line with Parallel Annotation")
fig.show()
The text was updated successfully, but these errors were encountered:
It's not particularly obvious that this is a bug because it may simply be too involves to have the text angles rotate adaptively as the figure size is changed but would be great to have!
The following snippet should produce a figure where the annotation is parallel to the line, however if the figure size changes the rotation of the annotation doesn't change.
The text was updated successfully, but these errors were encountered: