title: Plot Cassini ovals in Python using numpy and matplotlib
body: <p>I am trying to plot Cassini ovals in Python using these
  parametric equations for x,y.</p>
  <p><a href="https://mathcurve.com/courbes2d.gb/cassini/cassini.shtml" rel="nofollow noreferrer">https://mathcurve.com/courbes2d.gb/cassini/cassini.shtml</a></p>
  <p>Here is my program.</p>
  <pre><code>%matplotlib inline
  
  import numpy as np
  
  import matplotlib.pyplot as plt
  
  
  cnt = 20
  
  plt.figure(figsize=(12,8))
  
  for a in np.linspace(1,20,cnt):
  
      b = 0.9*a
  
      t = np.linspace(a + np.sqrt(a**2-b**2), a + np.sqrt(a**2+b**2),200)
      x = (b**4 - t**4)/(4*a*(t**2))
      y = np.sqrt(t**2 - ((x-a)**2))
  
      plt.plot(x, y)
      plt.plot(x, -y)
  </code></pre>
  <ol>
  <li><p>I am not sure if it works OK, I do get some nice plot but I am not sure if the Cassini ovals are full. Are they full/complete or just partially plotted? Btw, they just look like circles, not quite what I was hoping for.</p>
  </li>
  <li><p>When I increase <code>cnt</code> (say to 100), I start getting weird warnings <code>RuntimeWarning: invalid value encountered in sqrt: y = np.sqrt(t**2 - ((x-a)**2))</code> I don't know why I am not getting these warnings when cnt is smaller. Why am I getting these for larger values of <code>cnt</code>?</p>
  </li>
  </ol>
  <p>How can I fix this code?</p>
  <p>The first picture below is for <code>cnt=20</code>, the second one is for <code>cnt=100</code>.</p>
  <p>The second one has these blank areas, I think that's where the quantity under the sqrt sign becomes negative (or something), and probably that's when I get these warnings. But why? I just programmed literally the two parametric equations. I am not quite sure what's wrong.</p>
  <p><a href="https://i.stack.imgur.com/9MMkr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9MMkr.png" alt="d001" /></a></p>
  <p><a href="https://i.stack.imgur.com/WUKhh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WUKhh.png" alt="d002" /></a></p>