0
0
Matplotlibdata~10 mins

Creating custom style sheets in Matplotlib - Interactive Practice

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

Complete the code to apply a custom style sheet named 'mystyle' in matplotlib.

Matplotlib
import matplotlib.pyplot as plt
plt.style.use('[1]')
plt.plot([1, 2, 3], [4, 5, 6])
plt.show()
Drag options to blanks, or click blank then click option'
Aseaborn
Bdefault
Cmystyle
Dggplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using a built-in style name instead of the custom one.
Forgetting to put the style name in quotes.
2fill in blank
medium

Complete the code to save a custom style dictionary to a file named 'mystyle.mplstyle'.

Matplotlib
style_dict = {'lines.linewidth': 2, 'axes.titlesize': 14}
with open('[1]', 'w') as f:
    for key, value in style_dict.items():
        f.write(f"{key}: {value}\n")
Drag options to blanks, or click blank then click option'
Astyle.txt
Bconfig.cfg
Cstyle.json
Dmystyle.mplstyle
Attempts:
3 left
💡 Hint
Common Mistakes
Saving the style with a wrong file extension.
Using a filename that matplotlib won't recognize as a style sheet.
3fill in blank
hard

Fix the error in the code to correctly load a custom style sheet from a file path.

Matplotlib
import matplotlib.pyplot as plt
style_path = '/path/to/[1]'
plt.style.use(style_path)
plt.plot([1, 2], [3, 4])
plt.show()
Drag options to blanks, or click blank then click option'
Amystyle.mplstyle
Bstyle.cfg
Cmystyle.txt
Dcustomstyle.json
Attempts:
3 left
💡 Hint
Common Mistakes
Using a file with the wrong extension.
Not providing the full filename including extension.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that sets line width to 3 for all keys starting with 'lines.'.

Matplotlib
style_dict = {key: [1] for key in keys if key.[2]('lines.')}
Drag options to blanks, or click blank then click option'
A3
Bstartswith
Cin
Dendswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'in' instead of 'startswith' for filtering keys.
Setting the wrong value for line width.
5fill in blank
hard

Fill all three blanks to create a style dictionary that sets font size to 12 for axes titles, font family to 'serif', and line color to 'red'.

Matplotlib
style_dict = {
    'axes.titlesize': [1],
    'font.family': [2],
    'lines.color': [3]
}
Drag options to blanks, or click blank then click option'
A12
B'serif'
C'red'
D'12pt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers incorrectly.
Forgetting quotes around string values.