0
0
Matplotlibdata~10 mins

Font size guidelines in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the font size of the title to 16.

Matplotlib
import matplotlib.pyplot as plt
plt.title('Sample Plot', fontsize=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A12
B16
C20
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for fontsize.
Forgetting to set fontsize parameter.
2fill in blank
medium

Complete the code to set the font size of x-axis labels to 14.

Matplotlib
import matplotlib.pyplot as plt
plt.xlabel('X Axis', fontsize=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A20
B18
C14
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using fontsize too small to read.
Not passing fontsize parameter at all.
3fill in blank
hard

Fix the error in the code to set the font size of y-axis tick labels to 12.

Matplotlib
import matplotlib.pyplot as plt
ax = plt.gca()
plt.plot([1, 2, 3], [4, 5, 6])
plt.setp(ax.get_yticklabels(), fontsize=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A12
B'12'
C14
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Passing font size as a string instead of an integer.
Using plt.yticks(fontsize=12) instead of plt.setp for tick labels.
4fill in blank
hard

Fill both blanks to create a dictionary setting font sizes for title and labels.

Matplotlib
font_sizes = {'title': [1], 'label': [2]
Drag options to blanks, or click blank then click option'
A18
B14
C12
D16
Attempts:
3 left
💡 Hint
Common Mistakes
Using smaller font size for title than labels.
Using same font size for both title and labels.
5fill in blank
hard

Fill all three blanks to create a font size dictionary and apply it to a plot.

Matplotlib
font_sizes = {'title': [1], 'xlabel': [2], 'ylabel': [3]
import matplotlib.pyplot as plt
plt.title('My Plot', fontsize=font_sizes['title'])
plt.xlabel('X Axis', fontsize=font_sizes['xlabel'])
plt.ylabel('Y Axis', fontsize=font_sizes['ylabel'])
plt.show()
Drag options to blanks, or click blank then click option'
A18
B14
C12
D16
Attempts:
3 left
💡 Hint
Common Mistakes
Using same font size for all labels.
Setting ylabel font size larger than title.