Open in Colab

Plotting with Matplotlib and Seaborn

In [4]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [5]:
# Plot a single function
x = np.linspace(0, 10, 100)
plt.plot(x, np.cos(x))
Out[5]:
[<matplotlib.lines.Line2D at 0x116099518>]
In [8]:
# Import and init Seaborn
import seaborn as sns
sns.set()

# Same function, better looks!
plt.plot(x, np.cos(x))
Out[8]:
[<matplotlib.lines.Line2D at 0x1a19440cf8>]
In [10]:
# Plot a scatter plot
x = np.linspace(0, 10, 30)
plt.plot(x, np.sin(x), '-ok');
In [12]:
# Plot an histogram of 3 distributions
x1 = np.random.normal(0, 0.8, 1000)
x2 = np.random.normal(-2, 1, 1000)
x3 = np.random.normal(3, 2, 1000)

kwargs = dict(histtype='stepfilled', alpha=0.3, density=True, bins=40)

plt.hist(x1, **kwargs)
plt.hist(x2, **kwargs)
plt.hist(x3, **kwargs);
In [13]:
# Load the Iris dataset
iris = sns.load_dataset("iris")

# Plot the multidimensional relationships among the samples
sns.pairplot(iris, hue='species', size=2.5);