0
0
Matplotlibdata~10 mins

Axes vs pyplot interface comparison 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 line plot using pyplot interface.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.[1]()
Drag options to blanks, or click blank then click option'
Adraw
Bshow
Cplot
Dfigure
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.draw() instead of plt.show() which does not display the plot window.
Calling plt.figure() which creates a new figure but does not display the plot.
2fill in blank
medium

Complete the code to create a figure and axes using the object-oriented interface.

Matplotlib
import matplotlib.pyplot as plt
fig, [1] = plt.subplots()
[1].plot([1, 2, 3], [3, 2, 1])
plt.show()
Drag options to blanks, or click blank then click option'
Aaxis
Baxes
Cax
Dfigure
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'figure' instead of 'axes' which is the wrong object for plotting.
Using 'axis' which is not the correct variable name returned by plt.subplots().
3fill in blank
hard

Fix the error in the code by choosing the correct method to set the title using the axes object.

Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [3, 2, 1])
ax.[1]('My Plot')
plt.show()
Drag options to blanks, or click blank then click option'
Alabel
Btitle
Csetlabel
Dset_title
Attempts:
3 left
💡 Hint
Common Mistakes
Using ax.title() which does not exist for axes objects.
Using ax.label() which is unrelated to titles.
4fill in blank
hard

Fill both blanks to create a scatter plot using the axes interface and set x and y labels.

Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.[1]([1, 2, 3], [4, 5, 6])
ax.[2]('X axis')
ax.set_ylabel('Y axis')
plt.show()
Drag options to blanks, or click blank then click option'
Ascatter
Bset_xlabel
Cplot
Dxlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using ax.plot() instead of ax.scatter() for scatter plot.
Using ax.xlabel() which is not a method.
5fill in blank
hard

Fill all three blanks to create a bar chart using pyplot, set title and y label.

Matplotlib
import matplotlib.pyplot as plt
plt.[1](['A', 'B', 'C'], [5, 7, 3])
plt.[2]('Category Counts')
plt.[3]('Count')
plt.show()
Drag options to blanks, or click blank then click option'
Abar
Btitle
Cylabel
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot() instead of plt.bar() for bar chart.
Using plt.xlabel() instead of plt.ylabel() for y-axis label.