To create multiple plots in matplotlib, you can use the subplots
function. The subplots
function takes as input the number of rows and columns of subplots, and returns a figure and an array of axes objects.
Here's an example:
main.py339 chars20 lines
In this example, we generate two arrays of data, y1
and y2
, using the numpy
library. We then create a figure and an array of two axes objects using the subplots
function. We then call the plot
function on each of the axes objects to create the plots. Finally, we call the show
function to display the subplots.
You can adjust the number of rows and columns of subplots by changing the input to the subplots
function. For example, fig, axs = plt.subplots(3, 2)
would create a figure with 3 rows and 2 columns of subplots.
gistlibby LogSnag