This code will only show the arrow when zooming closely around x=50. Trying huge arrow sizes won’t show the arrow at all. How would you get an arrow on a line trace to show at all zoom levels?
In my real code (not the MRE below) I would like to have one or two large arrows at specific points on each line trace, where each line trace is 60-200 indices long. I’d like the arrows to show when no zoom is applied, as well as when zooming. While having them point in the direction of the two plot elements by which the arrow is defined using the annotation api (or the gradient of the chart at that point when the zoom level does not differentiate each data point).
Can that be accomplished?
import numpy as np
import pandas as pd
import plotly.express as px
# Sample data
np.random.seed(42)
df = pd.DataFrame({
'X': np.linspace(0, 200,200),
'Y1': np.random.randn(200).cumsum(),
'Y2': np.random.randn(200).cumsum()
})
# Create a line plot using Plotly Express
fig = px.line(df, x='X', y=['Y1', 'Y2'], title='Line Plot with Arrow Heads')
# Add arrows to the Scatter trace (Y1)
arrow_indices = [50] # Define arrow positions
for i in arrow_indices:
fig.add_annotation(
x=df['X'][i], y=df['Y1'][i],
ax=df['X'][i + 1], ay=df['Y1'][i + 1],
xref='x', yref='y', axref='x', ayref='y',
arrowhead=3, arrowsize=5, arrowwidth=3
)
# Show the figure
fig.show()
Or can we create an arrow shape without the annotation object (but same color as the trace it should be one) if that would afford a more natural solution?
Thanks!