title: Cannot Scatter, Plot, Show() In While Loop
body: <pre><code>import math
  import pylab as plt
  import numpy
  from numpy import sqrt
  from scipy.integrate import quad
  import random
  
  numpy.seterr(divide='ignore', invalid='ignore')
  def integrand (x):
      return sqrt(1-x**2)
      
  q1area, err = quad(integrand,0,1)
  
  print &quot;This program estimates the convergence of Pi to a ratio of one.&quot;
  while True:
      print &quot;Please choose from one of the five following options:&quot;
      print &quot; 1. 10^1\n 2. 10^2\n 3. 10^3\n&quot;
      choice = int(raw_input())
      options = {1,2,3}
          
      if choice == 1:
          plt.xlim([0,15])
          plt.ylim([-5,5])
  
          x = numpy.linspace(0,15,500)
          y = numpy.sqrt(1-x**2)
          z = 1+x*0
          
          xcord = []
          ycord = []
          under = []
          above = []
          pratiolist = []
          yvalues = []
          xvalues = range(1,11)
  
          for i in range(10):
              xcord.append(random.random())
              ycord.append(random.random())
  
          for j in ycord:
              if (j &lt;= q1area):
                  under.append(1)
      
              else:
                  above.append(1)
                  
              punder = len(under)
              if punder == 0:
                  punder = punder + 1
              
              pabove = len(above)
              if pabove == 0:
                  pabove = pabove + 1
              
              pratio = punder / float(pabove)
              pratiolist.append(pratio)
              
          for k in pratiolist:
              rtpi = k / float(math.pi)
              yvalues.append(rtpi)
          
          plt.scatter(xvalues,yvalues,c='b')
          plt.plot(x,z,'g')
          plt.show()
          
      if choice == 2:
          plt.xlim([0,110])
          plt.ylim([-5,5])
  
          x = numpy.linspace(0,110,500)
          y = numpy.sqrt(1-x**2)
          z = 1+x*0
          
          xcord = []
          ycord = []
          under = []
          above = []
          pratiolist = []
          yvalues = []
          xvalues = range(1,101)
  
          for i in range(100):
              xcord.append(random.random())
              ycord.append(random.random())
  
          for j in ycord:
              if (j &lt;= q1area):
                  under.append(1)
      
              else:
                  above.append(1)
                  
              punder = len(under)
              if punder == 0:
                  punder = punder + 1
              
              pabove = len(above)
              if pabove == 0:
                  pabove = pabove + 1
              
              pratio = punder / float(pabove)
              pratiolist.append(pratio)
              
          for k in pratiolist:
              rtpi = k / float(math.pi)
              yvalues.append(rtpi)
          
          plt.scatter(xvalues,yvalues,c='b')
          plt.plot(x,z,'g')
          plt.show()
          
      if choice == 3:
          plt.xlim([0,1100])
          plt.ylim([-5,5])
  
          x = numpy.linspace(0,1100,500)
          y = numpy.sqrt(1-x**2)
          z = 1+x*0
          
          xcord = []
          ycord = []
          under = []
          above = []
          pratiolist = []
          yvalues = []
          xvalues = range(1,1001)
  
          for i in range(1000):
              xcord.append(random.random())
              ycord.append(random.random())
  
          for j in ycord:
              if (j &lt;= q1area):
                  under.append(1)
      
              else:
                  above.append(1)
                  
              punder = len(under)
              if punder == 0:
                  punder = punder + 1
              
              pabove = len(above)
              if pabove == 0:
                  pabove = pabove + 1
              
              pratio = punder / float(pabove)
              pratiolist.append(pratio)
              
          for k in pratiolist:
              rtpi = k / float(math.pi)
              yvalues.append(rtpi)
              
          plt.scatter(xvalues,yvalues,c='b')
          plt.plot(x,z,'g')
          plt.show()
          
      while choice not in options:
          print &quot;Not a valid choice!\n&quot;
          break
          
  #plt.scatter(xvalues,yvalues,c='b')
  #plt.plot(x,z,'g')
  #plt.show()
  </code></pre>
  <p>The only way I can get the graphs to show is if I place break statements at the end of every if choice == 1,2,3, etc. and then place:</p>
  <pre><code>plt.scatter(xvalues,yvalues,c='b')
  plt.plot(x,z,'g')
  plt.show()
  </code></pre>
  <p>At the bottom of my code. This is inconvenient, I would like my to loop endlessly allowing choice between 1,2,3 without having to rerun the program. Why does Python's graphs crash when they are in whiles?</p>
  <h1>UPDATE</h1>
  <p>By using plt.draw(), I was able to get the graph to at least show but it still is not responding.</p>