0
for i in range(0,6):

   plt.figure(figsize=(5,5))

   for j in range(0,4):
       plt.plot([1,2,3,4,i,j])
    
   plt.title('sample plot')

   x = input('Enter sample id: ')

   if x == 's':
       print('s typed')
       print(' ')
    
   else:
       print('s not typed')
       print(' ')

for the example code above, I want to produce the plot and then have input which is processed by the following if statement, then the second for loop starts and do the same. For example, the code will loop 6 times I want to plot the first graph and have the first input and then have the second graph and the second input and so on, but what happens is when i run the code it asks me for input first and until I input 6 times it wont produce any plot. it produces all 6 plots after I give all inputs. You will understand what I mean once you run the code.

Do you know how to fix it in a way that I want? and why that happened?

Thank you for your help:)

1 Answer 1

1

I guess you have used plt.show() after your forloop. You should use plt.show() before asking input.

import matplotlib.pyplot as plt
for i in range(0,6):
   plt.figure(figsize=(5,5))
   for j in range(0,4):
       plt.plot([1,2,3,4,i,j])
    
   plt.title('sample plot')
   plt.show()
   x = input('Enter sample id: ')
   if x == 's':
       print('s typed')
       print(' ')    
   else:
       print('s not typed')
       print(' ')

This works for me as per your requirement

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.