Matplotlib Flashcards

1
Q

Basic plotting cycle: Plot sin and cos

A
x = np.linspace(0,10*math.pi,10000)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x,y1)
plt.plot(x,y2)
plt.show()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does plot() do?

A

A very complex function. Extremely versatile
Plot y versus x as lines and/or markers.

Call signatures::

plot([x], y, [fmt], *, data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)

The coordinates of the points or line nodes are given by x, y.

The optional parameter fmt is a convenient way for defining basicformatting like color, marker and linestyle.

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

Care to be taken with plt.show()

A

Use only onc3

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

Multiple show() commands can lead to

A

Unpredictable backend-dependent behavior

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

Embedding graphics directly in the notebook

A

%matplotlib notebook will lead to interactive plots embedded within the notebook
%matplotlib inline will lead to static images of your plot embedded in the notebook

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

Draw sin and cos’s with ‘-‘ and ‘–’ lines and save it to a file.

A

fig = plt.figure()

plt. plot(x, np.sin(x), ‘-‘)
plt. plot(x, np.cos(x), ‘–’);
fig. savefig(‘my_figure.png’)

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

list of supported file types can be found for your system by using the following method of the figure canvas object:

A

fig.canvas.get_supported_filetypes()

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

an instance of the class plt.Figure

A

a single container that contains all the objects representing axes, graphics, text, and labels.

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

Axes

A

The axes (an instance of the class plt.Axes) is what we see above: a bounding box with ticks and labels, which will eventually contain the plot elements that make up our visualization.

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