Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rid of grey background in python matplotlib bar chart

How do I get rid of the grey background in the plot below made using foll command in python matplotlib

ax.bar(x_axis,bar_val,yerr=err_val,linewidth=0,width=0.2)

enter image description here

like image 829
user308827 Avatar asked May 03 '15 00:05

user308827


People also ask

How do I make the background transparent in Matplotlib?

If you want to make something completely transparent, simply set the alpha value of the corresponding color to 0. For plt. savefig , there is also a "lazy" option by setting the rc-parameter savefig. transparent to True , which sets the alpha of all facecolors to 0%.

How do you change the background color of a bar 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.

How do I make a color transparent in Matplotlib?

Matplotlib allows you to regulate the transparency of a graph plot using the alpha attribute. By default, alpha=1. If you would like to form the graph plot more transparent, then you'll make alpha but 1, such as 0.5 or 0.25.


2 Answers

The set_axis_bgcolor function was deprecated in version 2.0. Use set_facecolor instead. Your code would be:

 ax.set_facecolor('white')
like image 156
harvpan Avatar answered Oct 08 '22 03:10

harvpan


Firstly, I should point out that the grey background is not the default for matplotlib. Are you using something like seaborn, which (inappropriately, in my opinion) messes with matplotlib's defaults by default whenever you import it?

As I'm assuming ax is already your axis, you can just do:

ax.set_axis_bgcolor('white')
like image 41
cge Avatar answered Oct 08 '22 01:10

cge