Libraries
Let's start by loading a few libraries:
- matplotlib: for plotting
- seaborn: for the themes
numpy
for data generationpandas
for storing the data
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd
Dataset
Our dataset will consist of 6 columns of numeric values:
data = np.random.normal(size=(20, 6)) + np.arange(6) / 2
df = pd.DataFrame(data)
df.head()
0 | 1 | 2 | 3 | 4 | 5 | |
---|---|---|---|---|---|---|
0 | -0.305213 | -0.850624 | -0.024465 | 0.992168 | 2.508927 | 0.833733 |
1 | 0.625631 | 1.469616 | 1.325944 | 1.108628 | 2.616785 | 1.712886 |
2 | -2.046518 | 0.102678 | 1.763569 | 1.885340 | 2.637508 | 2.632234 |
3 | 0.682349 | 0.591841 | 1.808995 | 1.269958 | 3.388124 | 3.758841 |
4 | -0.082201 | 0.391850 | 1.580840 | 1.603169 | 1.548844 | 0.812924 |
Default theme
sns.boxplot(data=data)
plt.show()
White grid
sns.set_style("whitegrid")
sns.boxplot(data=data)
plt.title("whitegrid")
plt.show()
Dark grid
sns.set_style("darkgrid")
sns.boxplot(data=data);
plt.title("darkgrid")
plt.show()
White
sns.set_style("white")
sns.boxplot(data=data);
plt.title("white")
plt.show()
Dark
sns.set_style("dark")
sns.boxplot(data=data);
plt.title("dark")
plt.show()
Ticks
sns.set_style("ticks")
sns.boxplot(data=data);
plt.title("ticks")
plt.show()
Going further
This post explains how to set the style of a seaborn plot.
You might be interested in how to custom axis in seaborn and how to add a title in seaborn