Complete the code to apply tight layout to the plot.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]() # Adjust spacing plt.show()
The tight_layout() function adjusts the spacing of subplots to prevent overlap.
Complete the code to create a figure and apply tight layout.
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([1, 2, 3], [3, 2, 1]) fig.[1]() plt.show()
Calling tight_layout() on the figure object adjusts spacing automatically.
Fix the error in the code to correctly apply tight layout.
import matplotlib.pyplot as plt fig, axs = plt.subplots(2, 1) axs[0].plot([1, 2, 3], [1, 4, 9]) axs[1].plot([1, 2, 3], [9, 4, 1]) plt.[1]() # Missing parentheses plt.show()
The tight_layout() function must be called with parentheses to execute.
Fill both blanks to create two subplots and apply tight layout.
import matplotlib.pyplot as plt fig, [1] = plt.subplots(1, 2) [2].plot([1, 2, 3], [3, 2, 1]) fig.tight_layout() plt.show()
When creating multiple subplots, axs is a list of axes. Use axs[0] to plot on the first subplot.
Fill all three blanks to create a figure with 3 subplots, plot on the second, and apply tight layout.
import matplotlib.pyplot as plt fig, [1] = plt.subplots(3, 1) [2].plot([1, 2, 3], [2, 4, 6]) fig.[3]() plt.show()
Multiple subplots return a list axes. Plot on the second subplot with axes[1]. Call tight_layout() on the figure to adjust spacing.