In a Python Plotly bar chart with two y-axes, how do I add horizontal lines using values from both y-axes?

163 Views Asked by At

I created a graph object bar chart that has two different y-axes so that I can chart two different of different units for each category. However, now I'd like to add two horizontal lines. They won't be using values from the same y-axis though.

fig = go.Figure(
    data=[
        go.Bar(name='Bar 1',
               x=category_x,
               y=measure_1,
               yaxis='y',
               offsetgroup=1),
        go.Bar(name='Bar 2',
               x=category_x,
               y=measure_2,
               yaxis='y2',
               offsetgroup=2)
    ]
)

Things look fine up to here.

Now, I'd like to add one horizontal line based off values from the first y-axis and another horizontal line based off values from the second y-axis. I tried using fig.add_hline() for this, but then both horizontal lines are displayed using values from the first y-axis. What should I be doing instead?

0

There are 0 best solutions below