'How to save two different matplotlib figures to two lists

data = pd.read_csv("Test data.csv")

test_data = np.array(data)

where the test_data is a time series dataset which dimension is 24×1024. Firstly, I use a for loop to draw all raw data and use map method to save raw figures in figs_list. the map method reference is here: Get the list of figures in matplotlib

def raw_data_draw():
    for i in range(len(test_data)):
        draw_data = test_data[i]
        plt.figure(figsize=(3.5,2.4),dpi=100)
        plt.xlim([0,1024])
        plt.ylim([0,1])
        plt.plot(draw_data)
        plt.title("signal %d"%i)
        
    global figs_list
    figs_list = list(map(plt.figure, plt.get_fignums()))
    return figs_list

secondly, I reshape the (24×1024) to (24×32×32) and draw grey scale images.

def grey_data_draw():
    for i in range(len(test_data)):
        grey_data = test_data.reshape(len(test_data),32,-1)
        plt.figure(figsize=(2.5,2.5),dpi=100)
        plt.imshow(grey_data[i],origin='lower', cmap=plt.cm.gray)
        plt.title("signal %d"%i)
    
    global grey_figs_list
    
    grey_figs_list = list(map(plt.figure, plt.get_fignums()))
    return grey_figs_list

Lastly, I run these two functions as follow and get two lists.

raw_data_draw()
grey_data_draw()

the figs_list should contain 24 time series plot and grey_figs_list should contain 24 grey images. I expect that figs_list and grey_figs_list contain different items, anyhow these tow lists contains same items,which seems figure were overwrited. I have searched much material but can not deal with it. Hope you can help me solve this problem, thanks in advance! :) the result is show as follow, where two lists contains same items.enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source