1 | initial version |
You can obtain subplots in matplotlib by using the subplots()
function. The subplots()
function creates a figure object and returns a tuple containing the figure and one or more subplots.
Here is an example code snippet:
import matplotlib.pyplot as plt
# Create a figure with two subplots
fig, axs = plt.subplots(2)
# Plot on the first subplot
axs[0].plot([1, 2, 3], [4, 5, 6])
axs[0].set_title('First Subplot')
# Plot on the second subplot
axs[1].plot([1, 2, 3], [2, 4, 6])
axs[1].set_title('Second Subplot')
# Show the plot
plt.show()
In this example, we create a figure with two subplots using the subplots()
function. We then plot on each subplot using the plot()
function and set a title for each subplot using the set_title()
function. Finally, we show the plot using the show()
function.