0
0
Matplotlibdata~10 mins

Diverging bar 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
Bnumpy
Cpandas
Dmatplotlib.pyplot
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like numpy or pandas.
Forgetting to import pyplot specifically.
2fill in blank
medium

Complete the code to create a horizontal bar chart using matplotlib.

Matplotlib
plt.barh([1], values, color=colors)
Drag options to blanks, or click blank then click option'
Avalues
Bcategories
Ccolors
Drange(len(values))
Attempts:
3 left
💡 Hint
Common Mistakes
Passing values instead of categories as the first argument.
Using bar instead of barh for horizontal bars.
3fill in blank
hard

Fix the error in the code to center the bars around zero for diverging values.

Matplotlib
plt.barh(categories, [1], color=colors)
Drag options to blanks, or click blank then click option'
Avalues - values.mean()
Bvalues - 0.5
Cvalues
D-values
Attempts:
3 left
💡 Hint
Common Mistakes
Using raw values without centering.
Subtracting a fixed number instead of the mean.
4fill in blank
hard

Fill both blanks to create a color list that colors positive values green and negative values red.

Matplotlib
colors = ['green' if val [1] 0 else 'red' for val in [2]]
Drag options to blanks, or click blank then click option'
A>
B<
Cvalues
Dcategories
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Using categories instead of values for color assignment.
5fill in blank
hard

Fill all three blanks to add labels and a title to the diverging bar chart.

Matplotlib
plt.xlabel('[1]')
plt.ylabel('[2]')
plt.title('[3]')
Drag options to blanks, or click blank then click option'
AScore
BCategory
CDiverging Bar Chart Example
DValue
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up x and y axis labels.
Using unclear or missing titles.