MatPlotLib
Graphics
import matplotlib.pyplot as plt- setup graph area:
fig, ax = subplots(figsize=(w,h))- resize figure:
fig.set_size_inches(w,h) - multiple plots:
fig, axes = subplots(nrows=2,ncols=3,figsize=(15,5))- affect individual plot:
axes[r,c].plot(x,y)
- affect individual plot:
- resize figure:
- plot:
ax.plot(x,y);- line plot is default
- scatterplot:
ax.plot(x, y, 'o');orax.scatter(x, y, marker='o'); - labels (methods) :
ax.set_xlabel(), ax.set_ylabel(), ax.set_title()
- save:
fig.savefig("Figure.png", dpi=400) - 3-dimensional data
- contour map:
ax.contour(x,y,z) - heatmap:
ax.imshow()
- contour map:
Additional Graphical and Numerical Summaries
- plot values in df columns:
ax.plot(df['col1'], df['col2'], 'o'); - use
df.plot()to call the variables by name and auto populate axes- i.e.
ax = Auto.plot.scatter('horsepower', 'mpg') - multiple plots in one chart:
Auto.plot.scatter('horsepower', 'mpg', ax=axes[1]);
- i.e.
- update column type:
pd.Series()- i.e.
Auto.cylinders = pd.Series(Auto.cylinders, dtype='category')
- i.e.
- boxplot:
df.boxplot() - histogram:
df.hist() - scatterplot matrix:
pd.plotting.scatter_matrix(df,figsize=(16,16)); - numerical summary:
df.describe()ordf[col].describe()
residual scatter plot:
ax = subplots(figsize=(8,8))[1]
ax.scatter(results.fittedvalues, results.resid)
ax.set_xlabel('Fitted value')
ax.set_ylabel('Residual')
ax.axhline(0, c='k', ls='--');
leverage scatter plot:
infl = results.get_influence()
ax = subplots(figsize=(8,8))[1]
ax.scatter(np.arange(X.shape[0]), infl.hat_matrix_diag)
ax.set_xlabel('Index')
ax.set_ylabel('Leverage')
you can plot a single variable super fast with df.plot(y='col')