sns.set_theme()
Changes the theme of the plots.
Common Palette Guideline
Seaborn provides a wide range of color palettes that you can use with the palette
parameter in sns.countplot()
or other Seaborn plots. Here is a breakdown of the options:
Palette Type | Palettes | |
Categorical | Designed for discrete variables with a few distinct categories. | deep , muted , bright , pastel , dark , colorblind |
Sequential | Suitable for ordered or continuous variables (e.g., intensity of values). | Blues , Greens , Oranges , Purples , Reds |
Diverging | Used for data with a meaningful midpoint, often centered around zero. | coolwarm , RdBu , PiYG , PuOr , Spectral |
Circular | Best for cyclical data like months or directions. | hsv , twilight , twilight_shifted |
Color Brewer | Set1 , Set2 , Set3 , Paired , Pastel1 , Dark2 , Accent | |
Gradient | cubehelix_palette , light_palette , dark_palette |
🎨 Seaborn Styling & Aesthetic Controls
Seaborn provides powerful options to control the look and feel of plots using global settings. These affect font size, background, gridlines, colors, context, and more.
1. Set Font Size
python
CopyEdit
sns.set(font_scale=1.25)
- 🔹
font_scale
adjusts the size of all text elements in a Seaborn plot: - Axis labels
- Tick labels
- Legend text
- Titles (if using
plt.title()
orax.set_title()
)
🧠 Tip: Use font_scale
to scale fonts globally rather than adjusting each element manually.
2. Set Background Style
python
CopyEdit
sns.set_style('darkgrid')
Available styles:
'white'
: Plain background with no grid.'whitegrid'
: White background with gridlines.'dark'
: Dark background, no grid.'darkgrid'
: Dark background with gridlines (default when plotting).'ticks'
: Adds ticks on axes; minimal style.
📌 Use sns.set_style(style_name)
to change background aesthetics.
3. Set Overall Context
python
CopyEdit
sns.set_context('notebook')
The context
affects the scaling of plot elements based on the setting’s purpose.
Available options:
'paper'
: Smallest size (good for print).'notebook'
: Medium (default).'talk'
: Larger (for presentations).'poster'
: Largest (for posters or large screens).
You can combine with font scaling:
python
CopyEdit
sns.set_context('talk', font_scale=1.25)
4. Set Global Aesthetic Settings at Once
python
CopyEdit
sns.set(
style='darkgrid', # Background style
context='notebook', # Scaling context
font_scale=1.25 # Font size
)
🧠 This is a one-liner to configure all the key aesthetics.
5. Despine Plots
python
CopyEdit
sns.despine()
Removes the top and right borders (spines) for a cleaner look.
You can also control which spines to remove:
python
CopyEdit
sns.despine(left=True, bottom=True)
6. Color Palette
python
CopyEdit
sns.set_palette('Set2') # Choose color set
Common palettes:
'deep'
(default)'muted'
'bright'
'pastel'
'dark'
'colorblind'
- Or define your own:
sns.set_palette(['#E24A33', '#348ABD'])
To preview:
python
CopyEdit
sns.color_palette('Set2')
7. Style Dictionaries for Custom Use
Each style (darkgrid
, whitegrid
, etc.) corresponds to a dictionary:
python
CopyEdit
sns.axes_style('whitegrid')
Returns a dictionary of parameters you can tweak directly.
You can also use:
python
CopyEdit
with sns.axes_style('ticks'):
sns.lineplot(...)
This applies the style only inside the with
block.
8. Reset to Default Settings
python
CopyEdit
sns.reset_defaults()
Returns Seaborn's settings to the library defaults.
Summary Table
Setting | Function | Purpose |
font_scale | sns.set(font_scale=x) | Scales text globally |
set_style() | sns.set_style('style') | Controls background and gridlines |
set_context() | sns.set_context('context') | Scales plot size for use-case |
set_palette() | sns.set_palette('palette') | Defines color scheme |
despine() | sns.despine() | Removes plot borders (spines) |
reset_defaults() | sns.reset_defaults() | Resets all styling |