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 horizontal bar chart using matplotlib.
plt.barh([1], values, color=colors)bar instead of barh for horizontal bars.The barh function needs the categories on the y-axis.
Fix the error in the code to center the bars around zero for diverging values.
plt.barh(categories, [1], color=colors)Subtracting the mean centers the bars around zero for diverging charts.
Fill both blanks to create a color list that colors positive values green and negative values red.
colors = ['green' if val [1] 0 else 'red' for val in [2]]
We check if each value is greater than zero to assign green, else red.
Fill all three blanks to add labels and a title to the diverging bar chart.
plt.xlabel('[1]') plt.ylabel('[2]') plt.title('[3]')
Labels describe the x-axis as 'Value', y-axis as 'Category', and the chart has a descriptive title.
