0

I have created a UI menu inside python by using a while true loop:

import matplotlib.pyplot as plt


choice=input('enter a number')
while True:
    if choice == '1':
        pass
    elif choice == '2':
        pass
    elif choice == '3':
        plt.plot(range(100),range(100))
        plt.show()

running it outside the while loop plots the graph just fine, but inside the loop, empty figures show up instead, and then python crashes.

why is it that i can't plot it inside the while loop.

Edit: I have been able to simplify the problem down to this:

import matplotlib.pyplot as plt

x,y=100
while True:
    plt.plot(x,y)

it seems the while True causes problems. any ideas?

1

2 Answers 2

3

Try using the plt.show() in the loop

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

3 Comments

i tried it. No luck
@S12312 I think the graphs fill up your memory please try to show some finite number of plots before going for infinte.. try 10, 20 then check by increasing number
ok, it seems that once i added the plt.show() it runs in other IDEs, but not pycharm console. It could be something to do with the fact that i am using console and not the regular run.
1
import matplotlib.pyplot as plt


choice=input('enter a number')
while True:
    if choice == '1':
        pass
    elif choice == '2':
        pass
    elif choice == '3':
        plt.plot(range(100),range(100))
        plt.show()
    choice=input('enter a number')

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.