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 the whole matplotlib instead of pyplot.
Importing unrelated libraries like numpy or pandas.
✗ Incorrect
Matplotlib's plotting functions are in the pyplot module, commonly imported as plt.
2fill in blank
mediumComplete the code to create a simple line plot using Matplotlib.
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
bar or hist which create different chart types.Using
scatter which plots points without connecting lines.✗ Incorrect
The plot function draws line plots connecting points.
3fill in blank
hardFix the error in the code to add a title to the plot.
Matplotlib
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 which label axes, not the title.Using
legend which adds a legend, not a title.✗ Incorrect
The title function adds a title to the plot.
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 creates a bar chart, and xlabel labels the x-axis.
5fill in blank
hardFill all three blanks to create a scatter plot with axis labels and a title.
Matplotlib
plt.[1]([1, 2, 3], [4, 5, 6]) plt.[2]('X Axis') plt.[3]('Y Axis') plt.title('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 for scatter plots.Mixing up
xlabel and ylabel.✗ Incorrect
scatter creates scatter plots, xlabel and ylabel label the axes.