Skip to content

add_hline() not working with secondary axis #3755

Closed
@Mo-Gul

Description

@Mo-Gul

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()

image showing the result of above code

As can be seen in the output, the hline is "linked" to the primary axis instead of to the secondary axis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions