sid8491
sid8491

Reputation: 6800

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.

Upvotes: 6

Views: 30180

Answers (1)

roob
roob

Reputation: 2529

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

Upvotes: 11

Related Questions