Newtt
Newtt

Reputation: 6190

Plotly not showing axis labels or title

I've got a Python project that displays a graph using plotly. This is my code:

def PlotData(data):
    trace1 = go.Scatter(
        y=PriceData,
        name="Prices",
        mode="lines+markers"
    )
    trace2 = go.Scatter(
        y=MarketData,
        name="Market Price",
        mode="lines+markers"
    )
    data = [trace1, trace2]
    layout = go.Layout(
        title='Plot Title',
        xaxis=dict(
            title='x Axis',
            titlefont=dict(
                family='Courier New, monospace',
                size=18,
                color='#7f7f7f'
            )
        ),
        yaxis=dict(
            title='y Axis',
            titlefont=dict(
                family='Courier New, monospace',
                size=18,
                color='#7f7f7f'
            )
        )
    )
    go.Figure(data=data, layout=layout)
    plotly.offline.plot(data)

The layout doesn't work as I get no titles or labels in the resultant graph. How do I fix this?

Upvotes: 2

Views: 9521

Answers (1)

Maximilian Peters
Maximilian Peters

Reputation: 31659

You are plotting data without any layout, not your Figure where you use your layout.

Try

fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig)

and it should work as expected

Upvotes: 6

Related Questions