0

I have data for several subjects and would like to make a plot for each of them. The goal is to loop through the individual subjects, extract the data for the current subject and then plot it. Once the data of the first subject is plotted, the program should stop and wait for user input, so that the plot for that subject can be inspected in peace. How is this possible?

Note: Im not interested in making subplots. Im working with PyCharm and the TkAgg Backend.

import matplotlib.pyplot as plt
import numpy as np


data_per_subject = [np.array([1,2]),
                    np.array([3,4]),
                    np.array([5,6])]

for data in data_per_subject:
    # open figure and plot data of current subject
    fig, ax = plt.subplots() 
    plt.plot(data) 

    # Here some magic has to take place, so that the program waits for my 
    # input. The importent thing is, that I have to be able to inspect 
    # the plot for the current subject while the programm is waiting for my 
    # input!

    # close figure
    plt.close()
zwithouta
  • 1,319
  • 1
  • 9
  • 22
  • Possible duplicate of https://stackoverflow.com/questions/4098131/how-to-update-a-plot-in-matplotlib and/or https://stackoverflow.com/questions/11874767/how-do-i-plot-in-real-time-in-a-while-loop-using-matplotlib – Guybrush Mar 28 '19 at 17:17
  • 1
    I think a simple `plt.show()` within your for loop instead of the `plt.close()` should be enough. `plt.show()` shows the figure and pauses the code until the figure is closed by the user. Then the for loop will continue until the next `plt.show()`. – Thomas Kühn Mar 29 '19 at 07:26

0 Answers0