Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting plot background colour in Seaborn

I am using Seaborn to plot some data in Pandas.

I am making some very large plots (factorplots).

To see them, I am using some visualisation facilities at my university. I am using a Compound screen made up of 4 by 4 monitors with small (but nonzero) bevel -- the gap between the screens. This gap is black. To minimise the disconnect between the screen i want the graph backgound to be black. I have been digging around the documentation and playing around and I can't work it out.. Surely this is simple.

I can get grey background using set_style('darkgrid')

do i need to access the plot in matplotlib directly?

like image 960
Lyndon White Avatar asked Aug 11 '14 08:08

Lyndon White


People also ask

What is the function to give color to plot in seaborn?

Seaborn provides a function called color_palette(), which can be used to give colors to plots and adding more aesthetic value to it.

How do you set the dark grid in seaborn plots?

Set the background to be darkgrid: Darkgrid appear on the sides of the plot on setting it as set_style('darkgrid'). palette attribute is used to set the color of the bars.

What is Hue in Python seaborn?

hue : (optional) This parameter take column name for colour encoding. data : (optional) This parameter take DataFrame, array, or list of arrays, Dataset for plotting. If x and y are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.


1 Answers

seaborn.set takes an rc argument that accepts a dictionary of valid matplotlib rcparams. So we need to set two things: the axes.facecolor, which is the color of the area where the data are drawn, and the figure.facecolor, which is the everything a part of the figure outside of the axes object.

(edited with advice from @mwaskom)

So if you do:

%matplotlib inline
import matplotlib.pyplot as plt
import seaborn
seaborn.set(rc={'axes.facecolor':'cornflowerblue', 'figure.facecolor':'cornflowerblue'})

fig, ax = plt.subplots()

You get:

enter image description here

And that'll work with your FacetGrid as well.

like image 130
Paul H Avatar answered Oct 15 '22 15:10

Paul H