If I have code like this :
import matplotlib.pyplot as plt
import numpy as np
time_axis = np.arange(0, 30 + 1 / 50, 1 / 50)
another_axis = np.arange(0, 10, 1)
grid = np.zeros((len(another_axis), len(time_axis)))
fig, ax = plt.subplots(12, 1, figsize=(10, 15), constrained_layout=True)
cbar = None
for i in range(12):
grid = np.random.random((len(another_axis), len(time_axis)))
pcm = ax[i].pcolormesh(time_axis, another_axis, grid, vmin=0, vmax=1)
cbar = fig.colorbar(pcm, ax=ax[i])
plt.show()
I have a problem when not all 12 grids can fit into memory at once. At the point that plt.show()
is called, is matplotlib holding memory proportional to 12*grid.size
? Is there anything I can do to reduce this or is this just the way plotting and pcolormesh work?