Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the matplotlib library for plotting.
Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing just 'matplotlib' does not give direct access to plotting functions.
Using 'pyplot' without 'matplotlib.' prefix causes an error.
✗ Incorrect
We import matplotlib.pyplot as plt to use plotting functions easily.
2fill in blank
mediumComplete the code to create a line plot of x and y data.
Matplotlib
plt.[1](x, y)
plt.show() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scatter' creates points without connecting lines.
Using 'bar' or 'hist' creates different chart types.
✗ Incorrect
The plot function creates a line plot connecting points.
3fill in blank
hardFix the error in the code to add a title to the plot.
Matplotlib
plt.title([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes causes a NameError.
Using mismatched quotes causes syntax errors.
✗ Incorrect
The title text must be a string enclosed in quotes.
4fill in blank
hardFill both blanks to create a bar chart with labels and show the plot.
Matplotlib
plt.[1](categories, values) plt.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'bar' creates a line plot.
Forgetting 'show' means the plot won't appear.
✗ Incorrect
Use bar to create a bar chart and show to display it.
5fill in blank
hardFill all three blanks to create a scatter plot with labels and a title.
Matplotlib
plt.[1](x, y) plt.xlabel([2]) plt.title([3]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'scatter' changes the plot type.
Forgetting quotes around labels causes errors.
✗ Incorrect
Use scatter for scatter plot, label x-axis with xlabel, and add a title with title.