0
0
Data Analysis Pythondata~20 mins

Figure and axes creation in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Figure and Axes Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this figure and axes creation code?
Consider the following Python code using matplotlib to create a figure and axes. What will be the type of the variable ax?
Data Analysis Python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
print(type(ax))
A<class 'matplotlib.axes._subplots.AxesSubplot'>
B<class 'tuple'>
C<class 'list'>
D<class 'matplotlib.figure.Figure'>
Attempts:
2 left
💡 Hint
The plt.subplots() function returns a figure and axes object. The axes object is used to plot data.
data_output
intermediate
1:30remaining
How many axes are created in this figure?
What is the number of axes created by the following code?
Data Analysis Python
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 3)
print(len(axs.flatten()))
A5
B3
C6
D2
Attempts:
2 left
💡 Hint
The plt.subplots(2, 3) creates a grid of 2 rows and 3 columns of axes.
🔧 Debug
advanced
2:00remaining
What error does this code raise?
Examine the code below. What error will it raise when run?
Data Analysis Python
import matplotlib.pyplot as plt
fig, ax = plt.subplots(2)
ax.plot([1, 2, 3], [4, 5, 6])
AAttributeError: 'numpy.ndarray' object has no attribute 'plot'
BTypeError: 'int' object is not iterable
CValueError: x and y must have same first dimension
DNo error, plots successfully
Attempts:
2 left
💡 Hint
When plt.subplots(2) is called, ax is an array of axes, not a single axes.
visualization
advanced
1:30remaining
Which option produces a figure with 4 subplots arranged in 2 rows and 2 columns?
Select the code snippet that creates a figure with 4 subplots arranged in 2 rows and 2 columns.
Afig, axs = plt.subplots(4, 1)
Bfig, axs = plt.subplots(2, 2)
Cfig, axs = plt.subplots(1, 4)
Dfig, axs = plt.subplots(3, 2)
Attempts:
2 left
💡 Hint
The first argument is number of rows, the second is number of columns.
🧠 Conceptual
expert
2:30remaining
What is the difference between fig.add_subplot() and plt.subplots()?
Choose the correct statement about the difference between fig.add_subplot() and plt.subplots() in matplotlib.
A<code>fig.add_subplot()</code> returns a figure object, while <code>plt.subplots()</code> returns only axes objects.
B<code>fig.add_subplot()</code> creates a new figure with multiple subplots, while <code>plt.subplots()</code> adds a subplot to an existing figure.
C<code>fig.add_subplot()</code> and <code>plt.subplots()</code> are identical and interchangeable.
D<code>fig.add_subplot()</code> adds a single subplot to an existing figure, while <code>plt.subplots()</code> creates a new figure and a grid of subplots.
Attempts:
2 left
💡 Hint
Think about whether a new figure is created or an existing figure is modified.