Matplotlib Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Import the pyplot module

A

import matplotlib.pyplot as plt

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

Allow plots to display in Jupyter Notebook cell

A

%matplotlib inline

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

Plot and display the visual

A

plt. plot()

plt. show()

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

Create a figure sized 12 wide and 5 high containing 2 rows and 3 columns of subplots

A

fig, axs = plt.subplots(2, 3, figsize=(12, 5) )

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

Create a line chart

A

ax.plot(x, y)

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

Add a super title to a figure

A

fig.suptitle(‘Main Title for Figure’)

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

Create a title for the top right corner axes of a 2x2 grid of subplots

A

axs[0,1].set_title(‘Subplot Title’)

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

Create a figure with two vertically stacked subplots that share the same x & y axis range and scale

A

fig, axes = plt.subplots(2, sharex=True, sharey=True)

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

Generate a vertical bar plot

A

ax.bar( bar_positions, bar_heights, width_of_bars)

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

Set x major tick marks and y minor tick mark locations

A

ax. set_xticks( locations_list)

ax. setyticks(locations_list, minor=True)

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

Set x tick labels rotated 90 degrees

A

Should be only used after ax.set_xticks() to ensure correct position

ax.set_xticklabels( labels_list, rotation=90)

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

Create a scatter plot

A

ax.scatter(x, y)

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

Create a histogram with 20 bins

A

ax.hist( x, bins = 20)

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

Create boxplots for columnA and columnB of dataframe

A

ax.boxplot( df[ [‘columnA’, ‘columnB’].values )

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

Set a subplot’s y-axis view limit range to 0-50

A

ax.set_ylim(0,50)

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

Remove tick marks from the top and bottom of the x-axis as well as any labels on the bottom x-axis

A

ax.tick_params(
axis=’x’, # changes apply to the x-axis
which=’both’, # affect both major and minor ticks
bottom=False, # bottom edge ticks are off
top=False, # top edge ticks are off
labelbottom=False) # bottom edge labels are off

17
Q

Remove all spines

A

ax. spines[“top”].set_visible(False)
ax. spines[“bottom”].set_visible(False)
ax. spines[“left”].set_visible(False)
ax. spines[“right”].set_visible(False)

                     -OR-

for key, spine in ax.spines.items():
spine.set_visible(False)
#spines is a dict and dict.items() unpacks key value tuples

18
Q

Annotate some text onto a subplot

A

ax.text( x, y, comment_str)