Matplotlib Basics Flashcards

1
Q

How do you draw a plot using matplotlib?

A

From matplotlib import pyplot as plt
Plt.plot()

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

What arguments does plt.plot() take and what do they mean?

A

Plt.plot() takes 2 main arguments, X and y values, then it can take additional arguments such as marker, colour,linewidth,label
X and y arguments decide how the plot looks, marker changes the way the line looks, colour changes the colour of the line, linewidth changes the weight of the line, label assigns a name that can later be displayed using plt.legend()

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

How do you name X and y axis?

A

You can use plt.xlabel(‘name’) and plt.ylabel(‘name’) to do that

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

How do you name the whole plot?

A

You can use plt.title(‘title’) to do that

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

How can you display the labels

A

You can use plt.legend() to do that

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

What arguments does plt.legend() take?

A

Plt.legend() takes loc= as argument, it can takes a string like ‘upper left’ as a value or a tuple which corresponds % of how far away from bottom left the legend should be, for example (0.02,0.05)

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

How do you create a grid?

A

You can use plt.grid(True)

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

How do you create a layout that fits on your display?

A

You can use plt.tight_layout()

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

How can you save what you made on your disc?

A

Plt.savefig(‘’)

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

How can you display the figure you made?

A

Plt.show()

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

How can you create a bar?

A

Plt.bar()

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

How can you create a horizontal bar plot

A

Plt.barh()

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

How can you create a pie chart?

A

Plt.pie()

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

What arguments can plt.pie() take and what do they do?

A

Labels,slices,colors,shadow,explode,wedgeprops={edgecolor:},startangle,autopct. Labels=labels names each slice, slices=slices sets a part for every slice, colors=colors sets a color for each slice, shadow=true creates a shadow for the pie, explode=Xplode gets one slice away from others. Autopct rounds the values

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

How can you create a scatterplot?

A

plt.scatter()

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

What arguments does scatterplot take and what do they change?

A

C,marker,alpha,edgecolor,cmap,s,X,y
C stands for color,s stands for size,marker changes the symbol, alpha sets how see through it is , X,y set coordinates, cmap sets the color scheme,edgecolor sets the color of the edge

17
Q

What’s a colorbar and how do you create it?

A

Colorbar is like a legend for the colours on the scatterplot
Clrbar= plt.colorbar()
Clrbar has it’s own functions for example clrbar.set_label(‘’)

18
Q

How would you change the X and y values to their logarithmic expressions

A

Plt.xscale(‘log’),plt.yscale(‘log’)

19
Q

How can you create a stack plot?

A

You can do that by using plt.stackplot()

20
Q

What arguments does the plt.stackplot() take?

A

X values , y values * n, labels,colors
X values argument sets X values there can only be one, yvalues set the y plane and are stacked on top of each other there can be multiple, labels=labels names the values, colors=colors gives the values set colors