Module 6 · Seaborn · Lesson 35 of 66

Style and color

Backgrounds, borders, sizes and color palettes.

In this lesson · about 8 minutes

  • Pick a background with set_style and remove borders with despine
  • Scale everything for a talk or poster with set_context
  • Choose colors with palette

A few calls change the look of every chart that follows:

  • sns.set_style('whitegrid'): the background. Options are 'white', 'whitegrid', 'dark', 'darkgrid' and 'ticks'.
  • sns.despine(): removes the top and right borders. Pass left=True or bottom=True to remove those too.
  • sns.set_context('talk'): scales text and lines for 'paper', 'notebook', 'talk' or 'poster'.
  • palette='...' on a plot, or sns.set_palette, picks the colors. Any Matplotlib color map name works, such as 'coolwarm', 'viridis', 'magma' or 'Set2'.

Each cell on this page starts from the default look, as if you'd restarted the notebook.

Exercise

Clean it up

Set the style to 'ticks', draw a count plot of sex, then remove the top and right borders.

Code that runs before yours
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset('tips')

Exercises solved: 0 of 1

Tip: solve each exercise first. Press Check to test your code.

Noviq Academy's Data Science course is free and for learning. Python runs in your browser with Pyodide, which downloads about 20 MB the first time, plus a few more for scikit-learn. Your code and progress stay on this device. The salaries data is a sample of San Francisco's public pay records; the purchases, customers, housing, advertising and classified data are made up. The Titanic, tips, flights and iris data sets come from Seaborn's examples; the maps use public 2011 to 2014 US and world figures. The 911 data is a 20,000-call sample of Montgomery County, Pennsylvania's public 911 records; the movie ratings are the MovieLens 100K data from GroupLens Research; the reviews are a 3,000-review sample from the Yelp Dataset Challenge; the loans are public LendingClub data; the colleges are the College data from An Introduction to Statistical Learning; the bank notes, kyphosis and breast cancer data come from the UCI Machine Learning Repository. Spark and TensorFlow can't run in a browser, so those lessons use stand-ins that run here, and show the code for the real tools.