The easiest option that comes to my mind is using subplot:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(4,216))
axs = fig.axes
gs = fig.add_gridspec(ncols=4, nrows=216)
axs = gs.subplots()
There we are creating a figure with 4x216 plots. Probably you will need to adjust the figsize to your desired dimentions.
To plot something you just need to acces the axis using its index. For example:
x = [1, 2, 3]
y = [[1, 2], [3, 4], [5, 6]]
axs[0,0].plot(x, y)
To save it you can use fig.savefig("plot.png")
. That creates a huge image. My suggestion is to create a pdf and store 4x6 plots per page. Here is an example of how to do it:
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages('plot.pdf')
for i in range(36):
fig = plt.figure(figsize=(16,24))
axs = fig.axes
gs = fig.add_gridspec(ncols=4, nrows=6)
axs = gs.subplots()
pp.savefig()
pp.close()
This process takes some time since it has to render a lot of images. Plotting a line made of 1000 random points (previously calculated) in each figure takes 37s. Here is the code of the test:
import time
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import numpy as np
start = time.time()
pp = PdfPages('plot.pdf')
xx = np.random.randint(0,100, 1000)
yy = np.random.randint(0,100, 1000)
for i in range(36):
print(i)
fig = plt.figure(figsize=(16,24))
axs = fig.axes
gs = fig.add_gridspec(ncols=4, nrows=6)
axs = gs.subplots()
for x in range(4):
for y in range(6):
axs[y,x].plot(xx, yy)
pp.savefig()
pp.close()
print(time.time() - start)