0
0
Matplotlibdata~10 mins

Dumbbell 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 import the matplotlib plotting library.

Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Aseaborn
Bmatplotlib.pyplot
Cpandas
Dnumpy
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like numpy or pandas instead of matplotlib.pyplot.
Forgetting to use 'as plt' for shorthand.
2fill in blank
medium

Complete the code to create a figure and axis for plotting.

Matplotlib
fig, ax = plt.[1]()
Drag options to blanks, or click blank then click option'
Asubplots
Bfigure
Cplot
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot() which only plots data but does not create axes.
Using plt.figure() which creates a figure but not axes.
3fill in blank
hard

Fix the error in the code to plot two points connected by a line for a dumbbell chart.

Matplotlib
ax.plot([1, 2], [[1], 5], marker='o', color='blue')
Drag options to blanks, or click blank then click option'
A7
B5
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same y-value twice, which plots a horizontal line.
Using a single number instead of a list of two numbers.
4fill in blank
hard

Fill both blanks to create a dumbbell chart connecting two sets of values for categories.

Matplotlib
ax.hlines(y=[1], xmin=[2], xmax=[1], color='gray', linewidth=2)
Drag options to blanks, or click blank then click option'
A[1, 2, 3, 4]
B[5, 6, 7, 8]
C[0, 1, 2, 3]
D[4, 5, 6, 7]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same list for y and xmin, which results in zero-length lines.
Swapping xmin and xmax values.
5fill in blank
hard

Fill all three blanks to complete the dumbbell chart code with points and lines.

Matplotlib
ax.scatter([1], [2], color='red', label='Start')
ax.scatter([3], [2], color='blue', label='End')
ax.hlines(y=[2], xmin=[1], xmax=[3], color='gray')
Drag options to blanks, or click blank then click option'
A[1, 2, 3, 4]
B[5, 6, 7, 8]
D[0, 1, 2, 3]
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up xmin and xmax values.
Using different y values for scatter and lines.