0
0
Matplotlibdata~10 mins

Fig, ax = plt.subplots pattern 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 create a figure and axes using plt.subplots.

Matplotlib
fig, ax = plt.[1]()
Drag options to blanks, or click blank then click option'
Afigure
Bplot
Csubplots
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot() instead of plt.subplots()
Using plt.figure() which returns only the figure, not axes
Trying to call plt.show() here which displays the plot
2fill in blank
medium

Complete the code to plot a line on the axes object.

Matplotlib
fig, ax = plt.subplots()
ax.[1]([1, 2, 3], [4, 5, 6])
Drag options to blanks, or click blank then click option'
Aplot
Bscatter
Chist
Dbar
Attempts:
3 left
💡 Hint
Common Mistakes
Using ax.scatter() which draws points, not lines
Using ax.hist() which draws histograms
Using ax.bar() which draws bar charts
3fill in blank
hard

Fix the error in the code to set the title of the axes.

Matplotlib
fig, ax = plt.subplots()
ax.set_[1]('My Plot Title')
Drag options to blanks, or click blank then click option'
Aylabel
Btitle
Cxlabel
Dlegend
Attempts:
3 left
💡 Hint
Common Mistakes
Using set_xlabel or set_ylabel which label axes, not title
Using set_legend which controls the legend
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths if length is greater than 3.

Matplotlib
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in the condition
Mapping word to word instead of length
Using len(word) in the condition but not in the value
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their values if the value is greater than 0.

Matplotlib
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using original key without uppercasing
Using wrong comparison operator like <
Using key instead of value in the dictionary values