0
0
Matplotlibdata~10 mins

Figure-level methods vs axes-level in Matplotlib - Interactive 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 matplotlib.

Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.[1]()
Drag options to blanks, or click blank then click option'
Ashow
Bfigure
Csubplots
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.figure() only creates a figure without axes.
Using plt.plot() does not create figure and axes objects.
2fill in blank
medium

Complete the code to plot data using the axes-level method.

Matplotlib
fig, ax = plt.subplots()
ax.[1]([1, 2, 3], [4, 5, 6])
plt.show()
Drag options to blanks, or click blank then click option'
Afigure
Bshow
Csubplots
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Calling plt.plot() instead of ax.plot() when using axes-level plotting.
Using ax.show() which does not exist.
3fill in blank
hard

Fix the error in the code by choosing the correct figure-level method to set the title.

Matplotlib
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
fig.[1]('My Plot Title')
plt.show()
Drag options to blanks, or click blank then click option'
Asuptitle
Btitle
Cset_title
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using ax.set_title() to set a figure title instead of a subplot title.
Using fig.title() which does not exist.
4fill in blank
hard

Fill both blanks to set the x and y labels using axes-level methods.

Matplotlib
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
ax.[1]('X Label')
ax.[2]('Y Label')
plt.show()
Drag options to blanks, or click blank then click option'
Aset_xlabel
Bset_ylabel
Cxlabel
Dylabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.xlabel() and plt.ylabel(), which are pyplot functions.
Using ax.xlabel(), which does not exist.
5fill in blank
hard

Fill all three blanks to set titles on two subplots using axes-level methods and a main title using figure-level method.

Matplotlib
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot([1,2,3], [1,2,3])
ax1.[1]('Left Plot')
ax2.plot([3,2,1], [1,2,3])
ax2.[2]('Right Plot')
fig.[3]('Comparison')
plt.show()
Drag options to blanks, or click blank then click option'
Aset_title
Bsuptitle
Ctitle
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using title() without set_ on axes.
Using suptitle() on individual axes instead of figure.