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.
Using unrelated libraries like pandas or numpy.
✗ Incorrect
We import matplotlib.pyplot as plt to create plots.
2fill in blank
mediumComplete the code to create a simple line plot with x and y data.
Matplotlib
plt.plot([1], [1, 4, 9, 16]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of numbers for x values.
Using lists of different length than y values.
✗ Incorrect
The x values should be numeric and match the length of y values.
3fill in blank
hardFix the error in the code to set the color of the line to blue.
Matplotlib
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], color=[1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the color name.
Using a color name that is not recognized.
✗ Incorrect
The color parameter expects a string with the color name in quotes.
4fill in blank
hardFill both blanks to create a scatter plot with red points and label the x-axis.
Matplotlib
plt.scatter([1, 2, 3], [4, 5, 6], color=[1]) plt.xlabel([2]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up x-axis and y-axis labels.
Using color names without quotes.
✗ Incorrect
The scatter points color is set to red and the x-axis label is 'X Axis'.
5fill in blank
hardFill all three blanks to create a bar chart with green bars, set the title, and label the y-axis.
Matplotlib
plt.bar(['A', 'B', 'C'], [5, 7, 3], color=[1]) plt.title([2]) plt.ylabel([3]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong color names or missing quotes.
Confusing title and axis labels.
✗ Incorrect
The bars are green, the chart title is 'Sales Data', and the y-axis label is 'Quantity'.