Matplotlib Flashcards

1
Q

How do you plot a numpy list?

A

import matplotlib.pyplot as plt

plt. plot(list_name, norm.pdf(list_name))
plt. show()

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

How do you plot multiple lists?

A

Use the plt.plot list as many times as necessary.

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

How do you save the current plot to a file?

A

plt.savefig(‘file_destination.png’, format=’png’)

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

How do you limit the axes to a certain range of numbers?

A

axes = plt.axes()

axes. set_xlim([-5,5])
axes. set_ylim([0,1.0])

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

How do you set the locations of the tick marks along the axes?

A

axes = plt.axes()

axes. set_xticks(list_of_xticks)
axes. set_yticks(list_of_yticks)

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

How do you add a grid to the graph?

A

axes.grid()

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

How do you write the extra pyplot.plot parameter controlling color and style?

A

‘r:’

First letter of the color, followed by a specific symbol.

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

What are the colors that can be represented with plotted lines?

A

red, green, blue, cyan, magenta, yellow, black, white

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

What are the styles that can be represented with plotted lines?

A
'-'	solid line style
'--'	dashed line style
'-.'	dash-dot line style
':'	dotted line style
'.'	point marker
','	pixel marker
'o'	circle marker
'v'	triangle_down marker
'^'	triangle_up marker
''	triangle_right marker
'1'	tri_down marker
'2'	tri_up marker
'3'	tri_left marker
'4'	tri_right marker
's'	square marker
'p'	pentagon marker
'*'	star marker
'h'	hexagon1 marker
'H'	hexagon2 marker
'+'	plus marker
'x'	x marker
'D'	diamond marker
'd'	thin_diamond marker
'|'	vline marker
'_'	hline marker
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you label axes?

A

plt. xlabel(‘—’)

plt. ylabel(‘—’)

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

How do you make a legend?

A

plt.legend([‘Title1’, ‘Title2’], loc=4)

The integer loc controls where the legend is.

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

How do you make a pie chart?

A

plt.pie(values, colors= colors, labels=labels, explode = explode)

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

What do the parameters for the pie chart represent?

A

Values: a list of integers representing percents of each slice (20 corresponds to a twenty-percent slice)
Colors: a list of characters corresponding to the RGB primary and secondary colors, plus black and white
Labels: a list of strings corresponding to the labels for each slice
Explode: a list of floats corresponding to how far removed the slice is from the center (0.0 means no explosion)

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

How do you give a plot a title?

A

plt.title(“Plot name”)

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

How do you make a bar chart?

A

plt.bar(range(0,5), values, color= colors)

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

What do the parameters for the bar chart represent?

A

Range: the x-axis range
Values: a list representing the size of each bin
Colors: a list of characters corresponding to the RGB primary and secondary colors, plus black and white

17
Q

How do you make a scatterplot from two lists?

A

plt. scatter(x_list, y_list)

plt. show()

18
Q

How do you make a histogram?

A

plt. hist(list_name, bin_size)

plt. show()

19
Q

How do you make a boxplot?

A

plt. boxplot(list_name)

plt. show()