plotly.py
plotly.py copied to clipboard
`add_hline()` not working with secondary axis
It was already "reported" at https://stackoverflow.com/q/67373687/5776000 that add_hline() is not working with a secondary axis. Here a bit more simplified MWE than given in the above link:
import plotly.express as px
import plotly.graph_objects as go
import numpy as np
df = px.data.iris()
fig = px.scatter(df, x="petal_length", y="petal_width")
fig.add_traces(go.Scatter(y=np.arange(1, 7), mode="lines+markers", yaxis='y2'))
fig.add_hline(y=2, line_dash='dash', line_color='Red', yref='y2')
fig.update_layout(
yaxis2=dict(
title="yaxis2 title",
overlaying="y",
side="right",
)
)
fig.show()

As can be seen in the output, the hline is "linked" to the primary axis instead of to the secondary axis.
I can confirm, experiencing the same issue where add_hline ignores yref argument and defaults to primary yaxis
Whoops, forgot to circle back to this issue. This has been fixed and can be closed! @Mo-Gul see PR #4177