Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Matplotlib plotting library.
Raspberry Pi
import matplotlib[1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .plot or .chart instead of .pyplot
Forgetting to import pyplot module
✗ Incorrect
The pyplot module in Matplotlib is imported as plt to create plots easily.
2fill in blank
mediumComplete the code to create a simple line plot of y values.
Raspberry Pi
plt.[1]([1, 2, 3, 4], [10, 20, 25, 30]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using scatter or bar instead of plot for line graphs
Not calling plt.show() to display the plot
✗ Incorrect
The plot() function creates a line plot connecting the points.
3fill in blank
hardFix the error in the code to add a title to the plot.
Raspberry Pi
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 label or xlabel instead of title
Forgetting to call plt.show()
✗ Incorrect
The title() function sets the title of the plot.
4fill in blank
hardFill both blanks to create a bar chart with labels and display it.
Raspberry Pi
plt.[1](['A', 'B', 'C'], [5, 7, 3]) plt.[2]('Categories') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plot() instead of bar() for bar charts
Using ylabel() instead of xlabel() for x-axis label
✗ Incorrect
bar() creates a bar chart, xlabel() labels the x-axis.
5fill in blank
hardFill all three blanks to create a scatter plot with axis labels and a title.
Raspberry Pi
plt.[1]([1, 2, 3, 4], [10, 20, 25, 30]) plt.[2]('X Axis') plt.[3]('My Scatter Plot') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plot() instead of scatter()
Mixing up xlabel() and title()
✗ Incorrect
scatter() creates scatter plots, xlabel() and title() label axes and title.
