Idan
Idan

Reputation: 5450

Change plot background color

Looking for advice of how to change the background color of the plotly plot to transparent?

I have looked around the docs, but could not find any reference.

pie_chart = {
  'data': [{
    'labels': ['V0', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9'],
    'values': [55, 22, 31, 32, 33, 45, 44, 42, 12, 67],
    'type': 'pie',
    'sort': false,
  }],

  'layout': {
    backgroundColor: "rgba(255,255,255,0.5)",
    width: 320,
  }

}

Plotly.newPlot('plot', pie_chart.data, pie_chart.layout);
#plot {
  background-color: lightblue;
}
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="plot"> </div>

Upvotes: 6

Views: 18979

Answers (3)

Donat Szecsko
Donat Szecsko

Reputation: 51

plot_bgcolor sets the color of plotting area in-between x and y axes.

paper_bgcolor sets the color of paper where the graph is drawn (= outside of axes but inside of parent div).

So for a transparent background you need to use both in layout section like this:

layout = {
   plot_bgcolor: "rgba(0,0,0,0)",
   paper_bgcolor: "rgba(0,0,0,0)"
}

Official reference: https://plot.ly/javascript/reference/#layout-paper_bgcolor

Upvotes: 3

Naren Murali
Naren Murali

Reputation: 56690

Please use paper_bgcolor property of layout to make it transparent.

paper_bgcolor (color):
default: "#fff"
Sets the color of paper where the graph is drawn.

From the official documentation, available here

pie_chart = {
  'data': [{
    'labels': ['V0', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9'],
    'values': [55, 22, 31, 32, 33, 45, 44, 42, 12, 67],
    'type': 'pie',
    'sort': false,
  }],

  'layout': {
    paper_bgcolor: "rgba(0,0,0,0)",
    width: 320,
  }

}

Plotly.newPlot('plot', pie_chart.data, pie_chart.layout);
#plot {
  background-color: lightblue;
}
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="plot"> </div>

Upvotes: 8

Sidhanshu_
Sidhanshu_

Reputation: 2110

pie_chart = {
  'data': [{
    'labels': ['V0', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9'],
    'values': [55, 22, 31, 32, 33, 45, 44, 42, 12, 67],
    'type': 'pie',
    'sort': false,
  }],

  'layout': {
    width: 320,
  }

}

Plotly.newPlot('plot', pie_chart.data, pie_chart.layout);
#plot {
  background-color: lightblue !important;
}
.main-svg {
   background-color: transparent !important;
}
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="plot"> </div>

Is it What you looking for ? Hope it helps!!

Upvotes: 1

Related Questions