#25 Histogram with several variables | Seaborn

If you have several numeric variables and want to visualize their distributions together, you have 2 options: plot them on the same axis (left), or split your windows in several parts (faceting, right). The first option is nicer if you do not have too many variable, and if they do not overlap much.


# Import library and dataset
import seaborn as sns
df = sns.load_dataset('iris')

# Method 1: on the same Axis
sns.distplot( df["sepal_length"] , color="skyblue", label="Sepal Length")
sns.distplot( df["sepal_width"] , color="red", label="Sepal Width")



# library and data
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

# plot
f, axes = plt.subplots(2, 2, figsize=(7, 7), sharex=True)
sns.distplot( df["sepal_length"] , color="skyblue", ax=axes[0, 0])
sns.distplot( df["sepal_width"] , color="olive", ax=axes[0, 1])
sns.distplot( df["petal_length"] , color="gold", ax=axes[1, 0])
sns.distplot( df["petal_width"] , color="teal", ax=axes[1, 1])

Leave a Reply

Your email address will not be published.