matplotlib.pyplot Flashcards

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

Import the function which enables you to create simple charts

A

import matplotlib.pyplot as plt

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

Which function is the most commonly used from the matplotlib module?

A

pyplot, usually as “plt” variable name

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

Create a line plot from x and y datasets

A

plt.plot(x, y)

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

Create a scatterplot from x and y datasets

A

plt.scatter(x, y)

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

Show the created plot

A

plt.show()

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

clean axis

A

plt.cla()

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

clean figure

A

plt.clf()

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

erase plots and release memory

A

plt.close()

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

Create a histogram from dataset x

A

plt.hist(x)

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

Create a histogram from dataset x with 30 bins

A

plt.hist(x, bins=30)

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

Modify the scale of the x axis to logarithmic scale

A

plt.xscale(‘log’)

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

We need a standard world development chart based on GDP per capita and life expectancy. You also have population to include as a third dimension (size), and you have information about the continent (color).

Corresponding numpy arrays:
gdp, life, pop, col.

Make the points slightly transparent to that they can be distinghuised if they are overlapping.

A

plt.scatter(x = gdp, y = life, s = pop, c = col, alpha = 0.8)

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

Include the following options on the scatterplot named plt already existing:

X label: “GDP”
Y label: “Life expectancy”
Title: “World Development”
X axis ticks: “1000, 10000, 100000” with the labels “1K”, “10K”, “100K”

A

plt. xlabel(“GDP”)
plt. ylabel(“Life expectancy”)
plt. title(“World Development”)
plt. xticks([1000,10000,100000], [“1K”, “10K”, “100K”])

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

Add custom text.

At coordinates 1550, 71, add “India”.

A

plt.text(1550, 71, “India”)

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

Turn on the grid

A

plt.grid(True)

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