matplotlib eats all memory when saving fig matplotlib eats all memory when saving fig
The solution for “matplotlib eats all memory when saving fig matplotlib eats all memory when saving fig” can be found here. The following code will assist you in solving the problem.
fig = plt.figure(num=1, clear=True)
for i in tqdm(range(55238, len(df)-40)):
df_tmp = df.iloc[i:i+30]
name = f’data/{i+30+1}’
generate_picture(df_tmp, name, fig)
gc.collect()import matplotlib.pyplot as plt
import numpy as np
A = np.arange(1,5)
B = A**2
cnt=0
while(1):
cnt = cnt+1
print(“########### test %d ###########” % cnt)
# here is the trick:
# set the figure a ‘num’ to prevent from re-malloc of a figure in the next loop
# and set “clear=True” to make the figure clear
# I never use plt.close() to kill the figure, because I found it doesn’t work.
# Only one figure is allocated, which can be self-released when the program quits.
# Before: 6000 times calling of plt.figure() ~ about 1.6GB of memory leak
# Now: the memory keeps in a stable level
fig = plt.figure(num=1, clear=True)
ax = fig.add_subplot()
# alternatively use an other function in one line
# fig, ax = plt.subplots(num=1,clear=True)
ax.plot(A,B)
ax.plot(B,A)
# Here add the functions you need
# plt.show()
fig.savefig(‘%d.png’ % cnt)
More questions on [categories-list]
- tss from gene granges
- ixl ansers ixl ansers
- get coin prices node-binance
- how to setup netflix workflow worker
- spritesheets in pyqt spritesheets in pyqt
- cahokia mounds pictures cahokia mounds pictures cahokia mounds pictures
- python 2 decimal places how to get decimal part of a double in python set number of decimals python
- how to find nuber of tweets per day using python how to find nuber of tweets per day using python how to find nuber of tweets per day using python how to find nuber of tweets per day using python how to find nuber of tweets per day using python
- haskell get specific elements of a String
- vb net code snippets for storing password
- error TS2307: Cannot find module ‘@ngx-meta/core’.
- inline scripts encapsulated in tags