Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a title to the plot.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]('My Plot') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using xlabel or ylabel instead of title.
Trying to add a legend without labels.
✗ Incorrect
The title function adds a title to the plot.
2fill in blank
mediumComplete the code to add grid lines to the plot.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.[1](True) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using legend instead of grid.
Trying to use axis to add grid lines.
✗ Incorrect
The grid(True) function adds grid lines to the plot for better readability.
3fill in blank
hardFix the error in the code to set x-axis label correctly.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.xlabel[1]('Time (s)') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Forgetting parentheses entirely.
✗ Incorrect
The xlabel function requires parentheses to pass the label string.
4fill in blank
hardFill both blanks to create a scatter plot with red color and circle markers.
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5, 6] plt.scatter(x, y, color=[1], marker=[2]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong quotes or missing quotes around color.
Using wrong marker symbols.
✗ Incorrect
The color parameter sets the color, and marker='o' sets circle markers.
5fill in blank
hardFill all three blanks to create a histogram with 10 bins, green color, and alpha transparency 0.5.
Matplotlib
import matplotlib.pyplot as plt data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] plt.hist(data, bins=[1], color=[2], alpha=[3]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of number for bins.
Forgetting quotes around color.
Using alpha values outside 0 to 1 range.
✗ Incorrect
The bins parameter controls the number of bars, color sets the bar color, and alpha sets transparency.