Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like 'yes' instead of a boolean.
Passing None which does not enable grid lines.
✗ Incorrect
Using plt.grid(True) turns on the grid lines on the plot.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'x' which shows grid lines on the horizontal axis.
Using None which disables grid lines.
✗ Incorrect
Setting axis='y' shows grid lines only along the y-axis.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word 'dashed' which is not recognized.
Using 'dotted' which creates dots, not dashes.
✗ Incorrect
The linestyle parameter accepts short codes like '--' for dashed lines.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number for color instead of a string.
Using a string for linewidth instead of a number.
✗ Incorrect
Use color='red' and linewidth=2 to style the grid lines.
5fill in blank
hardFill 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'
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'.
✗ Incorrect
Dashed lines use '--', color is 'green', and transparency is set with alpha=0.5.