Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Background color to transparent in Plotly plots

My python code creates a plotly Bar plot but the background is white in color i want to change it into transparent color is that doable

My Code:

import plotly.plotly as py from plotly.graph_objs import * py.sign_in('username', 'api_key') data = Data([ Bar(     x=['Sivaranjani S', 'Vijayalakshmi C', 'Rajeshwari S', 'Shanthi Priscilla', 'Pandiyaraj G', 'Kamatchi S', 'MohanaPriya', 'Madhumitha G', 'Franklin Alphones Raj J', 'Akfaris Almaas', 'Biswajit Champati', 'Priya R', 'Rekha Rajasekaran', 'Sarath Kumar B', 'Jegan L', 'Karthick A', 'Mahalakshmi S', 'Ragunathan V', 'Anu S', 'Ramkumar KS', 'Uthra R'],     y=[1640, 1394, 1390, 1313, 2166, 1521, 1078, 1543, 780, 1202, 1505, 2028, 2032, 1769, 1238, 1491, 1477, 1329, 2038, 1339, 1458],     text=['Scuti', 'Scuti', 'Cygni', 'Scorpii', 'Scuti', 'Pollux', 'Scorpii', 'Pollux', 'Scuti', 'Pollux', 'Scorpii', 'Scorpii', 'Scuti', 'Cygni', 'Scorpii', 'Scuti', 'Scuti', 'Pollux', 'Scuti', 'Pollux', 'Pollux'])]) plot_url = py.plot(data) 

The graph looks like this

enter image description here

like image 586
The6thSense Avatar asked Apr 30 '15 12:04

The6thSense


People also ask

How do I change my Plotly background?

The default theme starts out as "plotly" , but it can be changed by setting the plotly. io. templates. default property to the name of a registered theme.

How do you change the background color of a graph in Python?

We can set the Inner and Outer colors of the plot. set_facecolor() method is used to change the inner background color of the plot. figure(facecolor='color') method is used to change the outer background color of the plot.


1 Answers

For a fully transparent plot, make sure to specify both the paper bgcolor and the plot's:

import plotly.plotly as py from plotly.graph_objs import * py.sign_in('', '') data = Data([     Bar(         x=['Sivaranjani S', 'Vijayalakshmi C', 'Rajeshwari S', 'Shanthi Priscilla', 'Pandiyaraj G', 'Kamatchi S', 'MohanaPriya', 'Madhumitha G', 'Franklin Alphones Raj J', 'Akfaris Almaas', 'Biswajit Champati', 'Priya R', 'Rekha Rajasekaran', 'Sarath Kumar B', 'Jegan L', 'Karthick A', 'Mahalakshmi S', 'Ragunathan V', 'Anu S', 'Ramkumar KS', 'Uthra R'],         y=[1640, 1394, 1390, 1313, 2166, 1521, 1078, 1543, 780, 1202, 1505, 2028, 2032, 1769, 1238, 1491, 1477, 1329, 2038, 1339, 1458],         text=['Scuti', 'Scuti', 'Cygni', 'Scorpii', 'Scuti', 'Pollux', 'Scorpii', 'Pollux', 'Scuti', 'Pollux', 'Scorpii', 'Scorpii', 'Scuti', 'Cygni', 'Scorpii', 'Scuti', 'Scuti', 'Pollux', 'Scuti', 'Pollux', 'Pollux']     ) ])  layout = Layout(     paper_bgcolor='rgba(0,0,0,0)',     plot_bgcolor='rgba(0,0,0,0)' )  fig = Figure(data=data, layout=layout)  plot_url = py.plot(fig, filename='transparent-background') 
like image 170
etpinard Avatar answered Sep 16 '22 20:09

etpinard