Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 201
sid8491 Avatar asked Jul 19 '16 15:07

sid8491


People also ask

How do I change the background color in Plotly Python?

Plotly Express Set Transparent Color To create a transparent background, we can use the update_layout() function and bass the plot_bgcolor and paper_bgcolor transparent values.

How do you change your title color in Plotly?

@alexpetit12 You can set the font color for the entire title not only for substrings of it. layout=go. layout(title = dict(text ='Your title', font =dict(family='Sherif', size=14, color = 'red')), ... ) for more title attributes see https://plot.ly/python/reference/#layout-title.

How do you change the background color in Python?

Right-click the upper-left corner of the Python console window and select Properties. In the dialog box that appears, pick the tab labeled Colors. On it you can set the screen background and text color.

How do I add a background image in Plotly?

A background image can be added to the layout of a figure by setting the images parameter of plot_ly$layout . The source attribute of a layout$images can be the URL of an image, or an image object.


1 Answers

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'
    )
)
like image 64
roob Avatar answered Oct 08 '22 15:10

roob