Matplotlib Flashcards
What is the import necessary to use matplotlib in Python?
from matplotlib import pyplot as plt
What are the two types of interfaces for matplotlib?
MATLAB style stateful interface
OOP interface
Give six keyword arguments for the ax.plot() function
figsize color alpha linestyle marker label
How do you set x and y limits?
ax.set_xlim(…)
How do you set x and y labels?
ax.set_ylabel(…)
How do you set the title?
ax.set_title(…)
How do you do a scatter plot? Give some examples of the keyword arguments for this function
ax.scatter([paired_data], color=…, marker=…, …)
How do you make a histogram plot? How can you normalize this?
ax.hist([1d data], bins=50, density=True)
How do you plot a 2d histogram? How would you add a color bar?
hist_data = ax.hist2d([paired_data], …)
plt.colorbar(hist_data, ax=ax)
How would you make a contour plot? How would you specify the number of contours?
ax.contour(X,Y,Z, levels=20)
In Pandas, what is the best way of quickly visualizing the relationship between variables? How would you code this?
pd.plotting.scatter_matrix(df, figsize=…)
How would you plot a bar chart in Pandas?
df.plot(kind=’bar’)
How would you make a multiple bar chart plot? What if you wanted to stack this?
fig, axar = plt.subplots(1,2)
df1. plot(kind=’bar’, ax=axar[0])
df2. plot(kind=’bar’, ax=axar[1])
How would you make an area plot in Pandas? What if you don’t want to stack this?
df.plot.area(stacked=False)
How would you plot a histogram in Pandas? How would you stack this?
df.plot.hist(stacked=True)