Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a basic lollipop chart with matplotlib.
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [10, 15, 7, 12, 9] plt.stem(x, y, linefmt='grey', markerfmt='o', basefmt=' ') plt.xlabel('X axis') plt.ylabel('Y axis') plt.title('Basic Lollipop Chart') plt.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot() instead of plt.show() to display the plot.
Forgetting to call any function to display the chart.
✗ Incorrect
The plt.show() function displays the plot window with the lollipop chart.
2fill in blank
mediumComplete the code to set the color of the markers in the lollipop chart to red.
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [10, 15, 7, 12, 9] plt.stem(x, y, linefmt='grey', markerfmt='[1]', basefmt=' ') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bo' which sets blue markers instead of red.
Forgetting to include the marker style 'o' in the string.
✗ Incorrect
The markerfmt='ro' sets the marker color to red with circle markers.
3fill in blank
hardFix the error in the code to correctly plot a lollipop chart with custom line and marker colors.
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [10, 15, 7, 12, 9] plt.stem(x, y, linefmt=[1], markerfmt='ro', basefmt=' ') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using only 'grey' without a line style causes an error.
Using dashed or dotted line styles when a solid line is expected.
✗ Incorrect
The linefmt parameter requires a format string including color and line style, e.g., 'grey-'.
4fill in blank
hardFill both blanks to create a lollipop chart with green stems and blue circle markers.
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [10, 15, 7, 12, 9] plt.stem(x, y, linefmt=[1], markerfmt=[2], basefmt=' ') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up colors or line styles in the format strings.
Using 'ro' for markers when blue markers are requested.
✗ Incorrect
linefmt='g-' sets green solid lines; markerfmt='bo' sets blue circle markers.
5fill in blank
hardFill all three blanks to create a lollipop chart with x labels, y values, and a title.
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [10, 15, 7, 12, 9] plt.stem([1], [2], linefmt='grey-', markerfmt='ro', basefmt=' ') plt.[3]('Lollipop Chart Example') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping x and y data in the stem function.
Using plt.xlabel() instead of plt.title() for the chart title.
✗ Incorrect
The stem plot uses x and y data; plt.title() sets the chart title.