Python Matplotlib Visualization Quiz

Python
0 Passed
0% acceptance

A 35-question quiz covering Matplotlib figure structure, axes elements, line charts, labels, legends, and exporting plots.

35 Questions
~70 minutes
1

Question 1

What is the top-level container for all plot elements in Matplotlib?

A
The Axes
B
The Figure
C
The Canvas
D
The Plot
2

Question 2

Which command creates a new Figure and a single set of Axes using the object-oriented approach?

javascript

import matplotlib.pyplot as plt
# Create figure and axes
                
A
fig, ax = plt.subplots()
B
fig = plt.figure()
C
ax = plt.axes()
D
plt.plot()
3

Question 3

What is the relationship between a Figure and an Axes?

A
They are the same thing.
B
A Figure can contain multiple Axes, but an Axes belongs to only one Figure.
C
An Axes can contain multiple Figures.
D
A Figure is inside an Axes.
4

Question 4

How do you create a Figure with a grid of 2 rows and 3 columns of subplots?

javascript

fig, axes = plt.subplots(____, ____)
                
A
rows=2, cols=3
B
2, 3
C
3, 2
D
shape=(2, 3)
5

Question 5

What does `plt.show()` do?

A
It saves the plot to a file.
B
It triggers the rendering and display of all active figures.
C
It creates a new figure.
D
It clears the current plot.
6

Question 6

If you have `fig, axes = plt.subplots(2, 2)`, what is the data type of `axes`?

A
A single Axes object.
B
A list of Axes.
C
A NumPy array of Axes objects.
D
A dictionary.
7

Question 7

Which method sets the range (limits) of the x-axis?

A
ax.set_xrange()
B
ax.set_xlim()
C
ax.limit_x()
D
plt.range_x()
8

Question 8

How do you turn on the grid lines for a specific plot `ax`?

javascript

fig, ax = plt.subplots()
ax.plot([1, 2, 3])
# Turn on grid
                
A
ax.grid(True)
B
ax.show_grid()
C
plt.grid_on()
D
ax.set_grid('on')
9

Question 9

What are 'spines' in Matplotlib?

A
The lines connecting data points.
B
The axis lines connecting the axis tick marks and noting the boundaries of the data area.
C
The grid lines.
D
The title and labels.
10

Question 10

How would you remove the top and right spines from a plot `ax`?

javascript

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
                
A
The code above is correct.
B
ax.remove_spines('top', 'right')
C
ax.spines.hide(['top', 'right'])
D
plt.despine()
11

Question 11

What is the difference between `ax.set_xticks()` and `ax.set_xticklabels()`?

A
`set_xticks` sets the positions; `set_xticklabels` sets the text displayed at those positions.
B
They are aliases.
C
`set_xticks` sets the text; `set_xticklabels` sets the font.
D
`set_xticks` is for numbers; `set_xticklabels` is for strings.
12

Question 12

How do you set a logarithmic scale for the y-axis?

A
ax.set_yscale('log')
B
ax.log_y()
C
plt.scale('log')
D
ax.yaxis.log()
13

Question 13

Which method is used to draw a basic line chart?

A
ax.line()
B
ax.plot()
C
ax.chart()
D
ax.draw()
14

Question 14

How do you create a red dashed line with circle markers?

javascript

ax.plot(x, y, ____)
                
A
'r--o'
B
color='red', style='dashed', marker='circle'
C
'red-dashed-circle'
D
'o--r'
15

Question 15

You have two arrays `x` and `y`. How do you plot them?

A
ax.plot(x, y)
B
ax.plot(y, x)
C
ax.plot(x=x, y=y)
D
ax.graph(x, y)
16

Question 16

How do you change the line width to be thicker?

javascript

ax.plot(x, y, linewidth=____)
                
A
2
B
'thick'
C
True
D
bold
17

Question 17

What happens if you call `ax.plot()` multiple times on the same Axes?

A
The previous plot is erased.
B
The new plot is added to the existing one (superimposed).
C
It creates a new subplot.
D
It raises an error.
18

Question 18

How do you plot a line that is just markers (no connecting lines)?

A
ax.plot(x, y, linestyle='none', marker='o')
B
ax.scatter(x, y)
C
Both A and B work.
D
ax.plot(x, y, line=False)
19

Question 19

Which method sets the main title of the Axes?

A
ax.set_title('My Title')
B
ax.title('My Title')
C
plt.header('My Title')
D
ax.set_header('My Title')
20

Question 20

How do you label the x and y axes?

javascript

ax.set_xlabel('Time')
ax.set_ylabel('Velocity')
                
A
The code above is correct.
B
ax.xlabel('Time'); ax.ylabel('Velocity')
C
ax.set_labels('Time', 'Velocity')
D
plt.axes_labels('Time', 'Velocity')
21

Question 21

You want to add a text annotation at a specific coordinate (x=2, y=5). Which command do you use?

A
ax.text(2, 5, 'Look here')
B
ax.annotate('Look here', (2, 5))
C
ax.label(2, 5, 'Look here')
D
Both A and B work, but B is more powerful.
22

Question 22

How can you change the font size of the title?

A
ax.set_title('Title', fontsize=20)
B
ax.set_title('Title', size='big')
C
ax.title.set_size(20)
D
All of the above work (or are valid parameters).
23

Question 23

What is a 'suptitle'?

A
A super title for the entire Figure (above all subplots).
B
A subscript title.
C
A superior title style (bold).
D
A title at the bottom.
24

Question 24

How do you support mathematical expressions (LaTeX) in labels?

javascript

ax.set_xlabel(r'$E = mc^2$')
                
A
Enclose the string in dollar signs `$`.
B
Use the `latex=True` argument.
C
Import the latex library.
D
It is not supported.
25

Question 25

To display a legend, what must you provide when plotting data?

javascript

ax.plot(x, y, label='My Data')
ax.legend()
                
A
The `label` argument in the plot command.
B
The `name` argument.
C
The `id` argument.
D
Nothing, it guesses.
26

Question 26

How do you place the legend in the 'upper right' corner?

A
ax.legend(loc='upper right')
B
ax.legend(position='top right')
C
ax.legend(corner=1)
D
ax.set_legend('upper right')
27

Question 27

Can you create a legend without setting labels in `plot()`?

javascript

line1, = ax.plot(x, y1)
line2, = ax.plot(x, y2)
ax.legend([line1, line2], ['Label 1', 'Label 2'])
                
A
Yes, by passing handles and labels explicitly to `legend()`.
B
No, labels are mandatory in plot().
C
Yes, but only for one line.
D
No, it will raise an error.
28

Question 28

How do you remove the frame (box) around the legend?

A
ax.legend(frameon=False)
B
ax.legend(box=False)
C
ax.legend(border=None)
D
ax.legend(visible=False)
29

Question 29

What does `bbox_to_anchor` do in `legend()`?

A
It anchors the legend to a specific point, allowing placement outside the plot area.
B
It draws a box around the anchor.
C
It locks the legend so it cannot be moved.
D
It sets the background color.
30

Question 30

If you have multiple subplots, how do you create a single legend for the whole figure?

A
fig.legend()
B
plt.global_legend()
C
Call ax.legend() on every axis.
D
It is not possible.
31

Question 31

Which method saves the current figure to a file?

A
fig.save('plot.png')
B
fig.savefig('plot.png')
C
plt.export('plot.png')
D
fig.write('plot.png')
32

Question 32

How do you save a plot with a transparent background?

A
fig.savefig('plot.png', transparent=True)
B
fig.savefig('plot.png', alpha=0)
C
fig.savefig('plot.png', bg='none')
D
It is automatic for PNG.
33

Question 33

What does the `dpi` parameter control in `savefig()`?

A
Dots Per Inch (resolution).
B
Data Points Index.
C
Display Pixel Intensity.
D
Download Progress Indicator.
34

Question 34

Why might labels be cut off when saving a figure, and how do you fix it?

A
The figure size is too small. Fix with `bbox_inches='tight'`.
B
The font is too big. Fix by reducing font size.
C
It's a bug in Matplotlib.
D
You must use PDF format.
35

Question 35

Which file format is vector-based (infinite resolution)?

A
PNG
B
JPG
C
SVG
D
BMP

QUIZZES IN Python