Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Matplotlib plotting library.
Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing numpy or pandas instead of matplotlib.pyplot
Forgetting to import pyplot submodule
✗ Incorrect
Matplotlib's plotting functions are in the pyplot module, so we import it as matplotlib.pyplot.
2fill in blank
mediumComplete the code to create a simple line plot of y values.
Matplotlib
plt.[1]([1, 2, 3], [4, 5, 6]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using scatter instead of plot for line plots
Using hist or bar which are for other chart types
✗ Incorrect
The plot function draws a line plot connecting points.
3fill in blank
hardFix the error in the code to display the plot correctly.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1]) [1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling display() or draw() which do not exist in matplotlib
Forgetting to call any function to show the plot
✗ Incorrect
The show() function displays the plot window.
4fill in blank
hardFill both blanks to create a bar chart with labels.
Matplotlib
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() draws a bar chart. xlabel() adds a label to the x-axis.
5fill in blank
hardFill all three blanks to create a scatter plot with title and y-axis label.
Matplotlib
plt.[1]([1, 2, 3], [4, 5, 6]) plt.[2]('My Scatter Plot') plt.[3]('Values') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plot() instead of scatter() for scatter plots
Confusing xlabel and ylabel
Forgetting to add title
✗ Incorrect
scatter() creates a scatter plot. title() adds a title. ylabel() labels the y-axis.