Complete the code to import the matplotlib plotting library.
import [1] as plt
We import matplotlib.pyplot as plt to create plots.
Complete the code to create a figure and axis for plotting.
fig, ax = plt.[1]()The subplots() function creates a figure and axes for plotting.
Fix the error in the code to plot two points connected by a line for a dumbbell chart.
ax.plot([1, 2], [[1], 5], marker='o', color='blue')
The y-values must be two numbers to plot points connected by a line. Using 3 and 5 creates a line between points at y=3 and y=5.
Fill both blanks to create a dumbbell chart connecting two sets of values for categories.
ax.hlines(y=[1], xmin=[2], xmax=[1], color='gray', linewidth=2)
The horizontal lines are drawn at y positions from the categories list (e.g., [1, 2, 3, 4]). The xmin values are the smaller values (e.g., [0, 1, 2, 3]) to connect to xmax.
Fill all three blanks to complete the dumbbell chart code with points and lines.
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')
The y positions are the category indices [1, 2, 3, 4]. The start points are at xmin values [0, 1, 2, 3], and the end points are at xmax values [5, 6, 7, 8].