Plots Not Showing Up

I am trying to create a scatter graph with three traces as well as axes for each scatter graph. Here is my code. My data is located in a pandas table. For some reason, only the third trace is showing up in the main graph, but all three lines are showing up in the dragging application created at the bottom.

trace1 = go.Scatter(
            x = all_data['Date'],
            y = all_data['Revenue'],
            name = "Revenues",
            line = {'color': "#008000"},
            mode = 'lines')

trace2 = go.Scatter(
            x = all_data['Date'],
            y = all_data['total'],
            name = "Cost",
            line = {'color': "#ff0000"},
            mode = 'lines',
            yaxis='y2')

trace3 = go.Scatter(
            x=all_data['Date'],
            y=all_data['Visits'],
            name = "Visits",
            line = {'color': "#0000ff"},
            mode = 'lines',
            yaxis='y3')

day_data = [trace1, trace2, trace3]

layout = go.Layout(
    title='Revenue, Cost and Website Visits (Daily)',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label='1m',
                     step='month',
                     stepmode='backward'),
                dict(count=6,
                     label='6m',
                     step='month',
                     stepmode='backward'),
                dict(step='all')
            ])
        ),
        domain=[0.25, 0.75],
        rangeslider=dict(
            visible = True
        ),
        type='date'
    ),
    yaxis = dict(
        title='Revenue',
        titlefont=dict(
            color='#008000'
            ),
        tickfont=dict(
            color='#008000'
            ),
        anchor='x',
        overlaying='y',
        side='left',
        position=0
        ),
    yaxis2 = dict(
        title='Cost',
        titlefont=dict(
            color='#ff0000'
            ),
        tickfont=dict(
            color='#ff0000'
            ),
        anchor='x',
        overlaying='y',
        side='right',
        ),
    
    yaxis3=dict(
        title='Visits',
        titlefont=dict(
            color='#0000ff'
            ),
        tickfont=dict(
            color='#0000ff'
            ),
        anchor='free',
        overlaying='y',
        side='right',
        position=.95
        )
)

fig1 = go.Figure(data=day_data, layout=layout)

py.iplot(fig1)

csv: https://github.com/mcyee90/MedMen/blob/master/all_data.csv

Hi @mcyee90,

Could you update your post to put the code in a fenced code block? See https://help.github.com/articles/creating-and-highlighting-code-blocks/. This will keep the markdown renderer from messing up the formatting. Also, please include the imports and some sample data so that folks can copy and paste the code block and run it themselves.

Thanks!
-Jon

I think I updated it successfully, please let me know if there is anything else I can do?

Hi @mcyee90,

It looks like you need to remove overlaying='y' from yaxis. I’m not sure why it causes this exact problem, but removing it makes sense because yaxis can’t really overlay on top of itself. When I remove this one line, here’s what I get:

import plotly.graph_objs as go
import pandas as pd

all_data = pd.read_csv('https://raw.githubusercontent.com/mcyee90/MedMen/master/all_data.csv')

trace1 = go.Scatter(
            x = all_data['Date'],
            y = all_data['Revenue'],
            name = "Revenues",
            line = {'color': "#008000"},
            mode = 'lines')

trace2 = go.Scatter(
            x = all_data['Date'],
            y = all_data['total'],
            name = "Cost",
            line = {'color': "#ff0000"},
            mode = 'lines',
            yaxis='y2')

trace3 = go.Scatter(
            x=all_data['Date'],
            y=all_data['Visits'],
            name = "Visits",
            line = {'color': "#0000ff"},
            mode = 'lines',
            yaxis='y3')

day_data = [trace1, trace2, trace3]

layout = go.Layout(
    title='Revenue, Cost and Website Visits (Daily)',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label='1m',
                     step='month',
                     stepmode='backward'),
                dict(count=6,
                     label='6m',
                     step='month',
                     stepmode='backward'),
                dict(step='all')
            ])
        ),
        domain=[0.25, 0.75],
        rangeslider=dict(
            visible = True
        ),
        type='date'
    ),
    yaxis = dict(
        title='Revenue',
        titlefont=dict(
            color='#008000'
            ),
        tickfont=dict(
            color='#008000'
            ),
        anchor='x',
        # overlaying='y',
        side='left',
        position=0
        ),
    yaxis2 = dict(
        title='Cost',
        titlefont=dict(
            color='#ff0000'
            ),
        tickfont=dict(
            color='#ff0000'
            ),
        anchor='x',
        overlaying='y',
        side='right',
        ),
    
    yaxis3=dict(
        title='Visits',
        titlefont=dict(
            color='#0000ff'
            ),
        tickfont=dict(
            color='#0000ff'
            ),
        anchor='free',
        overlaying='y',
        side='right',
        position=.95
        )
)

fig1 = go.Figure(data=day_data, layout=layout)
py.iplot(fig1)

Hope that helps!
-Jon

Thanks so much for the help!

1 Like