0
0
Matplotlibdata~10 mins

Multiple histograms overlay 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'
Amatplotlib
Bmatplotlib.pyplot
Cpyplot
Dplt
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'matplotlib' directly instead of 'matplotlib.pyplot'.
Using 'import pyplot as plt' without 'matplotlib'.
2fill in blank
medium

Complete the code to create two lists of data for histograms.

Matplotlib
data1 = [1, 2, 3, 4, 5]
data2 = [1]
Drag options to blanks, or click blank then click option'
A[2, 3, 4, 5, 6]
B[5, 4, 3, 2, 1]
C[1, 1, 2, 2, 3]
D[6, 7, 8, 9, 10]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same list for both data sets.
Using an empty list.
3fill in blank
hard

Fix the error in the code to plot the first histogram with 5 bins.

Matplotlib
plt.hist(data1, bins=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'5'
B[5]
Cbins=5
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Passing bins as a string like '5'.
Passing bins as a list like [5].
4fill in blank
hard

Fill both blanks to plot two histograms overlayed with transparency.

Matplotlib
plt.hist(data1, bins=[1], alpha=[2])
plt.hist(data2, bins=5, alpha=0.5)
plt.show()
Drag options to blanks, or click blank then click option'
A5
B0.5
C1
D0.8
Attempts:
3 left
💡 Hint
Common Mistakes
Using different bins for the two histograms.
Using alpha=1 which hides the histogram underneath.
5fill in blank
hard

Fill all three blanks to add labels and a legend to the overlayed histograms.

Matplotlib
plt.hist(data1, bins=5, alpha=0.5, label=[1])
plt.hist(data2, bins=5, alpha=0.5, label=[2])
plt.[3]()
plt.show()
Drag options to blanks, or click blank then click option'
A"Data 1"
B"Data 2"
Clegend
Dshow_legend
Attempts:
3 left
💡 Hint
Common Mistakes
Not adding labels to histograms.
Using plt.show() instead of plt.legend() to show legend.