Seaborn
suggest changeSeaborn is a wrapper around Matplotlib that makes creating common statistical plots easy. The list of supported plots includes univariate and bivariate distribution plots, regression plots, and a number of methods for plotting categorical variables. The full list of plots Seaborn provides is in their API reference. The old stanford.edu/~mwaskom links no longer resolve to these pages.
Creating graphs in Seaborn is as simple as calling the appropriate graphing function. Here is an example of creating a histogram, kernel density estimation, and rug plot for randomly generated data.
import numpy as np # numpy used to create data for plotting
import seaborn as sns # common form of importing seaborn
# Generate normally distributed data
data = np.random.randn(1000)
# Plot a histogram with both a rugplot and kde graph superimposed
sns.distplot(data, kde=True, rug=True)
sns.distplot has been deprecated since seaborn 0.11. It is still present in 0.13.2, which is the current release, and was scheduled for removal in 0.14. These examples were not run here.
The style of the plot can also be controlled using a declarative syntax.
# Using previously created imports and data.
# Use a dark background with no grid.
sns.set_style('dark')
# Create the plot again
sns.distplot(data, kde=True, rug=True)
As an added bonus, normal matplotlib commands can still be applied to Seaborn plots. Here’s an example of adding axis titles to our previously created histogram.
# Using previously created data and style
# Access to matplotlib commands
import matplotlib.pyplot as plt
# Previously created plot.
sns.distplot(data, kde=True, rug=True)
# Set the axis labels.
plt.xlabel('This is my x-axis')
plt.ylabel('This is my y-axis')