0
0
Matplotlibdata~20 mins

Font properties customization in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Font Properties Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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()
A12
B10
C18
D24
Attempts:
2 left
💡 Hint
Look at the fontsize argument inside plt.title.
data_output
intermediate
1: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()
Aserif
Bsans-serif
Ccursive
Dmonospace
Attempts:
2 left
💡 Hint
Check the fontfamily argument in plt.xlabel.
visualization
advanced
2: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?
Aplt.title('Title', fontweight='bold', fontstyle='normal')
Bplt.title('Title', fontweight='italic', fontstyle='bold')
Cplt.title('Title', fontweight='normal', fontstyle='bold')
Dplt.title('Title', fontweight='bold', fontstyle='italic')
Attempts:
2 left
💡 Hint
fontweight controls boldness, fontstyle controls italic style.
🔧 Debug
advanced
1: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()
AThe code is correct and does not raise an error
Bplt.xlabel does not accept fontweight argument
Cfontweight should be set using plt.rcParams, not in xlabel
Dfontweight must be a string like 'bold', not an integer
Attempts:
2 left
💡 Hint
fontweight accepts both strings (like 'bold') and integers (like 700).
🚀 Application
expert
2: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?
A
plt.xlabel('X axis', fontstyle='italic', fontweight='bold', fontsize=14)
plt.ylabel('Y axis', fontstyle='italic', fontweight='bold', fontsize=18)
B
plt.xlabel('X axis', fontstyle='italic', fontsize=14)
plt.ylabel('Y axis', fontweight='bold', fontsize=18)
C
plt.xlabel('X axis', fontweight='bold', fontsize=18)
plt.ylabel('Y axis', fontstyle='italic', fontsize=14)
D
plt.xlabel('X axis', fontsize=14)
plt.ylabel('Y axis', fontsize=18)
Attempts:
2 left
💡 Hint
Check the fontstyle and fontweight parameters for each label separately.