TAGS :Viewed: 9 - Published at: a few seconds ago

[ How to set background color, title in Plotly (python)? ]

Below is my code, could someone tell me how do I set background color, title, x-axis y-axis labels :

scatterplot = plot([Scatter( x=x.index, y=x['rating'], mode='markers', marker=dict(size=10, color=x['value'], colorscale='Viridis', showscale=True), text=(x['value'] + ' ' + x['Episode'] + '<br>' + x['label']))], output_type='div')

P.S : this is being shown in webpage directly.

Answer 1


You can set background color by creating a Layout object

layout = Layout(
    plot_bgcolor='rgba(0,0,0,0)'
)

data = Data([
    Scatter( ... )  
])

fig = Figure(data=data, layout=layout)
plot(fig, output_type='div')

If you want a transparent background see this post.

To set the title and axis labels, add properties to the Layout object (see the docs):

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