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.
Forgetting to call plt.show() to display the plot.
✗ Incorrect
The title function adds a title to the plot.
2fill in blank
mediumComplete the code to label the x-axis as 'Time'.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]("Time") plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ylabel or title instead of xlabel.
Not calling plt.show() to display the plot.
✗ Incorrect
The xlabel function sets the label for the x-axis.
3fill in blank
hardFix the error in the code to label the y-axis as 'Speed'.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]('Speed') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'legends' instead of 'legend'.
Using xlabel or title instead of ylabel.
✗ Incorrect
The correct function to label the y-axis is ylabel.
4fill in blank
hardFill both blanks to add a title and label the x-axis.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]("Sales Over Time") plt.[2]("Year") plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping xlabel and ylabel.
Using legend instead of xlabel.
✗ Incorrect
Use title to add the plot title and xlabel to label the x-axis.
5fill in blank
hardFill all three blanks to add a title, label the x-axis, and label the y-axis.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]("Temperature Change") plt.[2]("Day") plt.[3]("Degrees Celsius") plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up xlabel and ylabel.
Using legend instead of axis labels.
✗ Incorrect
Use title for the plot title, xlabel for the x-axis label, and ylabel for the y-axis label.