2015-04-30 20 views
6

Il mio codice python crea una trama Bar plotly ma lo sfondo è di colore bianco voglio trasformarla in colore trasparente è che fattibilePython - Impostazione colore di sfondo a trasparente in Plotly trame

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) 

Il grafico appare così

enter image description here

risposta

15

per una trama completamente trasparente, assicurarsi di specificare sia il bgcolor carta e la trama del:

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

È possibile utilizzare un Layout per cambiarne i colori con i parametri bgcolour e opacity impostati sui propri desideri. Si potrebbe fare qualcosa di simile:

data = Data([Bar(... The same you already have...)]) 

layout = Layout(
    title='Your Title', 
    (xaxis, yaxis, WHAT EVER YOU WANT TO SET) 

    paper_bgcolor='rgb(233,233,233)', # set the background colour 

) 
fig = Figure(data=data, layout=layout) 
py.plot(fig) 

potete trovare alcuni esempi here

Problemi correlati