Matplotlib Flashcards

1
Q

What is the import necessary to use matplotlib in Python?

A

from matplotlib import pyplot as plt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two types of interfaces for matplotlib?

A

MATLAB style stateful interface

OOP interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give six keyword arguments for the ax.plot() function

A
figsize
color
alpha
linestyle
marker
label
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you set x and y limits?

A

ax.set_xlim(…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you set x and y labels?

A

ax.set_ylabel(…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you set the title?

A

ax.set_title(…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you do a scatter plot? Give some examples of the keyword arguments for this function

A

ax.scatter([paired_data], color=…, marker=…, …)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you make a histogram plot? How can you normalize this?

A

ax.hist([1d data], bins=50, density=True)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you plot a 2d histogram? How would you add a color bar?

A

hist_data = ax.hist2d([paired_data], …)

plt.colorbar(hist_data, ax=ax)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would you make a contour plot? How would you specify the number of contours?

A

ax.contour(X,Y,Z, levels=20)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In Pandas, what is the best way of quickly visualizing the relationship between variables? How would you code this?

A

pd.plotting.scatter_matrix(df, figsize=…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you plot a bar chart in Pandas?

A

df.plot(kind=’bar’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you make a multiple bar chart plot? What if you wanted to stack this?

A

fig, axar = plt.subplots(1,2)

df1. plot(kind=’bar’, ax=axar[0])
df2. plot(kind=’bar’, ax=axar[1])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you make an area plot in Pandas? What if you don’t want to stack this?

A

df.plot.area(stacked=False)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How would you plot a histogram in Pandas? How would you stack this?

A

df.plot.hist(stacked=True)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you do a box plot in Pandas?

A

df.plot.box()

17
Q

How do you save a figure in Pandas?

A

fig, ax=…

fig.save()