Bug: Candlesticks with multiple y-axes is not displayed

When trying to display candlesticks on a y-axis with a lower index than another y-axis, the candlesticks do not show.
Simple example:

import plotly.graph_objects as go
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
fig = go.Figure()

fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open'], 
                             high=df['AAPL.High'],
                             low=df['AAPL.Low'],
                             close=df['AAPL.Close'], yaxis='y1')
              )
fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.Low'], yaxis='y2'))
fig.show()

results in


It is peculiar that the xrange slider does still display the trace. I deliberately did not update the y-axes to make everything as simple as possible.

Switching the yaxis names such that the Scatter has yaxis='y1' and the Candlestick has yaxis='y2' results in expected behaviour as can be seen here:


However, this solution does not work when displaying multiple candlesticks on separate y-axes, as then all but the last candlestick will not be displayed.
Now there is another workaround to this by using secondary y-axis in make_subplots from plotly.subplots, but this is limited to only two y-axes and, as far as I know, wouldn’t work for more than two y-axes. Possibly, the bug is related to go.Candlestick with Subplots.

If I understand your question correctly then I believe what you want is to give all the candlesticks the same axis β€˜y1’ and the scatterplots the other β€˜y2’.
Then you can set it so that β€˜y2’ is overlaying β€˜y1’ like this:

fig = go.Figure()

fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open'], 
                             high=df['AAPL.High'],
                             low=df['AAPL.Low'],
                             close=df['AAPL.Close'], yaxis='y1')
              )
fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open']+20, 
                             high=df['AAPL.High']+20,
                             low=df['AAPL.Low']+20,
                             close=df['AAPL.Close']+20, yaxis='y1')
              )
fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open']+40, 
                             high=df['AAPL.High']+40,
                             low=df['AAPL.Low']+40,
                             close=df['AAPL.Close']+40, yaxis='y1')
              )
fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.Low'], yaxis='y2'))
fig.update_layout(yaxis2=dict(overlaying='y1', side='right'))
fig.show()

Thank you for the quick reply, but no, this is not what I want. I want to have multiple candlestick traces (let’s say 4) all on different y-axes (such that the different axes can be scaled indepedently). The Candlesticks may share the y-axis with one or several Scattergl traces.
The overlaying does appear to solve this problem as well. However, it is still unclear why overlaying is required at all. When doing the same thing but with Scattergls, there is no problem at all.

fig = go.Figure()

fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.Open'], yaxis='y1'))
fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.Low'], yaxis='y1'))
fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.High']+20, yaxis='y2'))
fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.Low']+40, yaxis='y3'))
fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.Close']+60, yaxis='y4'))

fig.update_layout(
    xaxis=dict(
        domain=[0.3, 0.7]
    ),
    yaxis=dict(
        title="yaxis title",
        titlefont=dict(
            color="#1f77b4"
        ),
        tickfont=dict(
            color="#1f77b4"
        )
    ),
    yaxis2=dict(
        title="yaxis2 title",
        titlefont=dict(
            color="#ff7f0e"
        ),
        tickfont=dict(
            color="#ff7f0e"
        ),
        anchor="free",
        side="left",
        position=0.15
    ),
    yaxis3=dict(
        title="yaxis3 title",
        titlefont=dict(
            color="#d62728"
        ),
        tickfont=dict(
            color="#d62728"
        ),
        anchor="x",
        side="right"
    ),
    yaxis4=dict(
        title="yaxis4 title",
        titlefont=dict(
            color="#9467bd"
        ),
        tickfont=dict(
            color="#9467bd"
        ),
        anchor="free",
        side="right",
        position = 0.85
    ),
)
fig.show()

shows all traces and all y-axes, whereas

fig = go.Figure()

fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open'], 
                             high=df['AAPL.High'],
                             low=df['AAPL.Low'],
                             close=df['AAPL.Close'], yaxis='y1')
              )
fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open']+20, 
                             high=df['AAPL.High']+20,
                             low=df['AAPL.Low']+20,
                             close=df['AAPL.Close']+20, yaxis='y2')
             )
fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open']+40, 
                             high=df['AAPL.High']+40,
                             low=df['AAPL.Low']+40,
                             close=df['AAPL.Close']+40, yaxis='y3')
              )
fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open']+60, 
                             high=df['AAPL.High']+60,
                             low=df['AAPL.Low']+60,
                             close=df['AAPL.Close']+60, yaxis='y4')
              )
fig.update_layout(<exact same as above>)
fig.show()

only shows the trace on yaxis=y4. Do you by any chance know the reasoning behind this?

I’m not completely sure but it seems to me that it has to do with there being more than one type of graph.

So if you try this with scattergl then you get the same result, the candlesticks don’t show:

fig = go.Figure()

fig.add_trace(go.Candlestick(x=df['Date'],
                             open=df['AAPL.Open'], 
                             high=df['AAPL.High'],
                             low=df['AAPL.Low'],
                             close=df['AAPL.Close'], yaxis='y1'))

fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.Open'], yaxis='y2'))

fig.show()

Yes exactly, the candlesticks in that example don’t show, but they (and the scattergl) do show in

fig = go.Figure()

fig.add_trace(go.Scattergl(x=df['Date'], y=df['AAPL.Open'], yaxis='y1'))

fig.add_trace(go.Candlestick(x=df['Date'],

                             open=df['AAPL.Open'], 

                             high=df['AAPL.High'],

                             low=df['AAPL.Low'],

                             close=df['AAPL.Close'], yaxis='y2'))

fig.show()

so it is absolutely mystifying that the one of the traces is hidden in the first case, but none are hidden in this case.
Thank you for the tip about overlaying, I think it’ll help me forward

use scaleanchor=β€˜y1’ instead of the overlaying

so you indicate that your y2 axis will have the same width as the y1 axis