0
0
Matplotlibdata~20 mins

Font size guidelines in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Font Size Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the font size of the title in this plot?

Consider the following matplotlib code that sets font sizes for different parts of a plot. What will be the font size of the plot's title?

Matplotlib
import matplotlib.pyplot as plt
plt.figure()
plt.title('Sample Title', fontsize=16)
plt.xlabel('X-axis', fontsize=12)
plt.ylabel('Y-axis', fontsize=12)
plt.show()
A12
B10
C16
D14
Attempts:
2 left
💡 Hint

Look at the fontsize argument inside the plt.title() function.

data_output
intermediate
2:00remaining
What is the font size of x-axis tick labels after this code?

Given the code below, what will be the font size of the x-axis tick labels?

Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
for tick in ax.get_xticklabels():
    tick.set_fontsize(14)
plt.show()
A12
B14
C10
D16
Attempts:
2 left
💡 Hint

Check the loop where set_fontsize is called on each tick label.

visualization
advanced
2:00remaining
Identify the font size used for the legend text

Look at the code below that creates a plot with a legend. What font size will the legend text have?

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], label='Line 1')
plt.plot([3, 2, 1], label='Line 2')
plt.legend(fontsize='small')
plt.show()
A8 (x-small)
B12 (medium)
C14 (large)
D10 (small)
Attempts:
2 left
💡 Hint

The fontsize argument in plt.legend() can take string values like 'small'.

🧠 Conceptual
advanced
2:00remaining
Why use relative font sizes in matplotlib?

Which of the following is the best reason to use relative font sizes (like 'small', 'medium', 'large') instead of fixed numeric sizes in matplotlib?

ARelative sizes automatically adjust when changing figure size or DPI, keeping proportions consistent.
BRelative sizes prevent any font size changes from user input.
CRelative sizes allow using any font family without errors.
DRelative sizes are faster to render than numeric sizes.
Attempts:
2 left
💡 Hint

Think about how plots scale on different screens or when saved at different resolutions.

🔧 Debug
expert
2:00remaining
Why does this font size setting not apply to axis labels?

Examine the code below. The user wants to set the font size of axis labels to 14, but the labels remain small. What is the cause?

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.rcParams['font.size'] = 14
plt.show()
AThe font size is set after the labels are created, so it does not affect existing labels.
BThe font size must be set using plt.xlabel(fontsize=14) instead of rcParams.
CrcParams['font.size'] only affects tick labels, not axis labels.
DThe plot command overrides all font size settings.
Attempts:
2 left
💡 Hint

Consider when rcParams changes take effect relative to plot commands.