0
0
Matplotlibdata~10 mins

Shared axes between subplots 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 two subplots sharing the x-axis.

Matplotlib
import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(2, sharex=[1])
ax1.plot([1, 2, 3], [1, 4, 9])
ax2.plot([1, 2, 3], [2, 3, 4])
plt.show()
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'False' instead of 'True' disables sharing.
Using 'None' does not enable sharing.
Using '0' is not a valid boolean.
2fill in blank
medium

Complete the code to create subplots sharing both x and y axes.

Matplotlib
fig, axs = plt.subplots(2, 2, sharex=[1], sharey=[2])
axs[0, 0].plot([1, 2, 3], [1, 2, 3])
axs[1, 1].plot([1, 2, 3], [3, 2, 1])
plt.show()
Drag options to blanks, or click blank then click option'
AFalse
BTrue
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting only one axis to share.
Using 'False' disables sharing.
Using 'None' does not enable sharing.
3fill in blank
hard

Fix the error in the code to share the y-axis between subplots.

Matplotlib
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=[1])
ax1.plot([1, 2, 3], [3, 2, 1])
ax2.plot([1, 2, 3], [1, 2, 3])
plt.show()
Drag options to blanks, or click blank then click option'
ATrue
BNone
CFalse
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '1' instead of 'True'.
Using 'None' disables sharing.
Using 'False' disables sharing.
4fill in blank
hard

Fill both blanks to create subplots sharing the x-axis and set figure size.

Matplotlib
fig, axs = plt.subplots(2, 1, sharex=[1], figsize=([2], 6))
axs[0].plot([1, 2, 3], [1, 4, 9])
axs[1].plot([1, 2, 3], [9, 4, 1])
plt.show()
Drag options to blanks, or click blank then click option'
ATrue
BFalse
C8
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'False' disables sharing.
Setting figure width too small or too large.
Confusing height and width values.
5fill in blank
hard

Fill all three blanks to create a 2x2 grid of subplots sharing y-axis and set figure size.

Matplotlib
fig, axs = plt.subplots(2, 2, sharey=[1], figsize=([2], [3]))
axs[0, 0].plot([1, 2, 3], [3, 2, 1])
axs[1, 1].plot([1, 2, 3], [1, 2, 3])
plt.show()
Drag options to blanks, or click blank then click option'
ATrue
BFalse
C6
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'False' disables sharing.
Swapping width and height values.
Using too small figure size causing cramped plots.