0
0
Matplotlibdata~10 mins

Lollipop charts in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Abar
Bplot
Cscatter
Dshow
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.
2fill in blank
medium

Complete 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'
A'ro'
B'ko'
C'go'
D'bo'
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.
3fill in blank
hard

Fix 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'
A'grey--'
B'grey-'
C'grey'
D'grey:'
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.
4fill in blank
hard

Fill 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'
A'g-'
B'ro'
C'bo'
D'k-'
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.
5fill in blank
hard

Fill 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'
Ax
By
Ctitle
Dxlabel
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.