0
0
Matplotlibdata~10 mins

Grid lines configuration 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 show grid lines on the plot.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.grid([1])
plt.show()
Drag options to blanks, or click blank then click option'
AFalse
BTrue
C'yes'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like 'yes' instead of a boolean.
Passing None which does not enable grid lines.
2fill in blank
medium

Complete the code to set grid lines only on the y-axis.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.grid(axis=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'y'
B'x'
C'both'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'x' which shows grid lines on the horizontal axis.
Using None which disables grid lines.
3fill in blank
hard

Fix the error in the code to set grid line style to dashed.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.grid(linestyle=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'dotted'
B'dashed'
C'--'
D'solid'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word 'dashed' which is not recognized.
Using 'dotted' which creates dots, not dashes.
4fill in blank
hard

Fill both blanks to set grid color to red and line width to 2.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.grid(color=[1], linewidth=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A'red'
B2
C1
D'blue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number for color instead of a string.
Using a string for linewidth instead of a number.
5fill in blank
hard

Fill all three blanks to create a grid with dashed green lines and alpha transparency 0.5.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.grid(linestyle=[1], color=[2], alpha=[3])
plt.show()
Drag options to blanks, or click blank then click option'
A'--'
B'green'
C0.5
D'solid'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dashed' instead of '--' for linestyle.
Using a string for alpha instead of a number.
Using a color name other than 'green'.