Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

matplotlib eats all memory when saving fig

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)
Comment

matplotlib eats all memory when saving fig

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()
Comment

PREVIOUS NEXT
Code Example
Typescript :: ts-node command compile typescript 
Typescript :: how to print the elements of a array using range based for loop 
Typescript :: post data 
Typescript :: nest cache 
Typescript :: get all fields of mongoose schema typescript 
Typescript :: PYTHON STACK FUNCTION count the valid number of brackets Returns the total number of valid brackets in the string 
Typescript :: xargs / parallel 
Typescript :: gets syntax 
Typescript :: 3 dots react 
Typescript :: the html element that houses all html element that contains meta information about the web page,importing external stylesheets and internal ces 
Typescript :: INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. 
Typescript :: ioredis 
Typescript :: token authentication requirements for git operations 
Typescript :: .setRowHeights google script 
Typescript :: You’re asked to read a file a line at a time. For each line, you have to split it into fields. Which of the following sets of pseudo class definitions is likely to be more orthogonal? 
Typescript :: git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 
Cpp :: fast i/o in c++ 
Cpp :: unistall lutris 
Cpp :: unreal engine delay c++ 
Cpp :: ue4 spawn actor c++ 
Cpp :: log base c++ 
Cpp :: prime number generator c++ 
Cpp :: should i learn c or c++ 
Cpp :: erosion and dilation c++ 
Cpp :: make_move_iterator 
Cpp :: c++ while loop decrement 
Cpp :: How to block window resize sfml c++ 
Cpp :: c++ split long code 
Cpp :: landscape overleaf 
Cpp :: access first value in a set c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =