In Jupyter Notebook, I write the following code, as MCVE:
import matplotlib.pyplot as plt
import numpy as np
x1 = np.linspace(-1, 1, 50)
for x in range(4):
plt.figure()
plt.plot(x1)
plt.savefig(str(x)+".png") # save figures separately
It produces 4 plots, as expected. They are below each other in a row.
I want to have a single saved output, containing all 4 plots. I don't mind if Jupyter Notebook does not show the plots as long as they are saved.
My attempt: save the figures separately, as 0.png, 1.png, 2.png, 3.png, then merge them vertically.
I hope there is an easier way to do this. How can I have a single saved output?
EDIT:
As suggested, I could do subplots, like this:
fig,axes = plt.subplots(nrows=4)
fig.set_size_inches(8,12)
x1 = np.linspace(-1, 1, 50)
for ax in axes:
ax.plot(x1)
plt.savefig("save_fig.png")
I want to have many figures, not one fiugre with many subplots. How can I save the multiple figures without using subplots?