Challenge - 5 Problems
Font Properties Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the font size of the title in this plot?
Consider this matplotlib code that sets a title with a specific font size. What font size will the title text have?
Matplotlib
import matplotlib.pyplot as plt plt.title('Sample Title', fontsize=18) plt.plot([1, 2, 3], [4, 5, 6]) plt.show()
Attempts:
2 left
💡 Hint
Look at the fontsize argument inside plt.title.
✗ Incorrect
The fontsize parameter in plt.title sets the font size of the title text. Here it is set to 18.
❓ data_output
intermediate1:30remaining
What font family is used in this text?
This code sets the font family of a label. What font family will the label text use?
Matplotlib
import matplotlib.pyplot as plt plt.xlabel('X axis', fontfamily='serif') plt.plot([1, 2], [3, 4]) plt.show()
Attempts:
2 left
💡 Hint
Check the fontfamily argument in plt.xlabel.
✗ Incorrect
The fontfamily parameter sets the font family. Here it is set to 'serif'.
❓ visualization
advanced2:00remaining
Which option produces a plot with bold and italic title text?
Given these four code snippets, which one will produce a plot with the title text both bold and italic?
Attempts:
2 left
💡 Hint
fontweight controls boldness, fontstyle controls italic style.
✗ Incorrect
fontweight='bold' makes text bold, fontstyle='italic' makes text italic. Option D sets both correctly.
🔧 Debug
advanced1:30remaining
Why does this code raise an error?
This code tries to set font properties but raises an error. What is the cause?
Matplotlib
import matplotlib.pyplot as plt plt.xlabel('X axis', fontweight=700) plt.show()
Attempts:
2 left
💡 Hint
fontweight accepts both strings (like 'bold') and integers (like 700).
✗ Incorrect
The code is correct and does not raise an error. Matplotlib's fontweight accepts numeric values from 0-1000 (700 is bold) in addition to strings like 'bold'.
🚀 Application
expert2:30remaining
How to set different font properties for x and y axis labels in one plot?
You want the x-axis label to be italic and size 14, and the y-axis label to be bold and size 18. Which code snippet achieves this?
Attempts:
2 left
💡 Hint
Check the fontstyle and fontweight parameters for each label separately.
✗ Incorrect
Option B correctly sets x label italic with size 14 and y label bold with size 18.