Matplotlib

Frecuently used Matplotlib code

Recipes

Make the plot larger in notebook

# one off
# In the chunk you want to plot
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(18, 16), dpi= 80, facecolor='w', edgecolor='k')
# new default
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [18, 16]

Correlation plot

import seaborn as sns
corr = data.corr()
ax = sns.heatmap(
    corr, 
    vmin=-1, vmax=1, center=0,
    cmap=sns.diverging_palette(20, 220, n=200),
    square=True
)
ax.set_xticklabels(
    ax.get_xticklabels(),
    rotation=45,
    horizontalalignment='right'
);
ax

2D plot of pandas dataframe

# data is DataFrame(pandas)
data.plot('A','B')

Last updated