title: While point in polygon plot points/lines fails (Circle.contains_point; Python; matplotlib; pyplot)
body: <p><strong>My task:</strong> Plot an initial point and calculate new point positions (x, y) while points are in a circle.</p>
  <p><strong>My problem:</strong> Using a <code>while</code> loop to perform this fails to run the code block as it incorrectly determines the circle doesn't contain the point (fig 1). However, using a <code>for</code> loop it can be seen that multiple points reside in the circle, but still incorrectly identifies that points don't exist in the circle (fig 2).</p>
  <p><strong>Additional info:</strong> I also can't seem to get lines instead of points to be plotted (e.g. using <code>pyplot.plot(x, y, '-')</code>).
  If there are more streamlined methods, for instance in plotting the circle/points/lines, or the entire approach I'd be interested to see them. I appreciate any help that can be offered.</p>
  <p>After much searching here and elsewhere I've come as far as the following code:</p>
  <pre><code># IMPORT LIBRARIES ####
  import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.path as mPath
  import matplotlib.patches as mPatches
  
  
  # CREATE CIRCLE ####
  # Input circle radius
  circleRadius = 2
  
  # Create circle (arguments: centre, radius, face colour (fc), edge colour (ec), alpha)
  circle = mPatches.Circle((0, 0), radius = circleRadius, fc = 'm', alpha = 0.3)
  
  # Plot circle
  fig1, ax = plt.subplots()
  ax.add_patch(circle)
  ax.set_xlim(-5, 5)
  ax.set_ylim(-5, 5)
  ax.set_aspect('equal')
  
  
  # CREATE POINTS ####
  # Input coordinates
  x0 = -1
  y0 = 0.5
  # Assignment for equation
  x = x0
  y = y0
  
  # Store
  curr_pt = [x, y]
  counter = 0
  
  # Plot 1st point (x, y)
  plt.plot(x, y, '.c')
  
  # Pre-checks
  print(circle.contains_point([x, y]))
  print(counter)
  print(x0, y0)
  print(x, y)
  
  # Plot points 
  while circle.contains_point([x, y]): # see 1st figure
  #for i in range(5):                  # uncomment this line (for) and comment above line (while) see 2nd figure
      xnew = x**2 - y**2 + x0
      ynew = 2 * x * y + y0
      x = xnew
      y = ynew
      # Update current point
      curr_pt = [x, y]
      # Plot point (x, y)
      plt.plot(x, y, '.c')
      counter += 1
  
  # Post-checks
  print(circle.contains_point([x, y]))
  print(counter)
  print(x0, y0)
  print(x, y)
  print(xnew, ynew) # note this check will output error with while loop as they will not be defined
  
  # Print plot
  plt.show()
  </code></pre>
  <p><strong>Output:</strong></p>
  <pre><code># while loop (Fig 1)
  False
  0
  -1 0.5
  -1 0.5
  False
  0
  -1 0.5
  -1 0.5
  </code></pre>
  <p><a href="https://i.stack.imgur.com/37sLu.png" rel="nofollow noreferrer">Fig 1 (while loop)</a></p>
  <pre><code># for loop (Fig 2)
  False
  0
  -1 0.5
  -1 0.5
  False
  5
  -1 0.5
  5.063203536206856 -4.162733919918537
  5.063203536206856 -4.162733919918537
  </code></pre>
  <p><a href="https://i.stack.imgur.com/BC5G4.png" rel="nofollow noreferrer">Fig 2 (for loop)</a></p>