Complete the code to create two subplots sharing the x-axis.
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()
Setting sharex=True makes the subplots share the x-axis.
Complete the code to create subplots sharing both x and y axes.
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()
Setting both sharex and sharey to True shares both axes.
Fix the error in the code to share the y-axis between subplots.
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()
To share the y-axis, sharey must be set to True.
Fill both blanks to create subplots sharing the x-axis and set figure size.
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()
Setting sharex=True shares the x-axis. The figure width is set to 8 inches.
Fill all three blanks to create a 2x2 grid of subplots sharing y-axis and set figure size.
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()
Sharing the y-axis is enabled with True. The figure size is set to 8 inches wide and 6 inches tall.
