Home > Software engineering >  Graphs not plotting when in while loop menu
Graphs not plotting when in while loop menu

Time:04-07

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?

CodePudding user response:

Try using the plt.show() in the loop

CodePudding user response:

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')
  • Related