Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
Setting sharex=True makes the subplots share the x-axis.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting only one axis to share.
Using 'False' disables sharing.
Using 'None' does not enable sharing.
✗ Incorrect
Setting both sharex and sharey to True shares both axes.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '1' instead of 'True'.
Using 'None' disables sharing.
Using 'False' disables sharing.
✗ Incorrect
To share the y-axis, sharey must be set to True.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'False' disables sharing.
Setting figure width too small or too large.
Confusing height and width values.
✗ Incorrect
Setting sharex=True shares the x-axis. The figure width is set to 8 inches.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'False' disables sharing.
Swapping width and height values.
Using too small figure size causing cramped plots.
✗ Incorrect
Sharing the y-axis is enabled with True. The figure size is set to 8 inches wide and 6 inches tall.