In [1]:
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display,Math
In [2]:
display(Math('(y - k)^2 + (x - h)^2 = r^2'))
$\displaystyle (y - k)^2 + (x - h)^2 = r^2$
In [3]:
h = 2
k = -3
r = 3

axlim = r + np.max((abs(h),abs(k)))
x = np.linspace(-axlim,axlim,100)
X,Y = np.meshgrid(x,x)

plt.imshow(X)
Out[3]:
<matplotlib.image.AxesImage at 0x115b5aac8>
In [4]:
plt.imshow(Y)
Out[4]:
<matplotlib.image.AxesImage at 0x115d352b0>
In [5]:
Fxy = (X-h)**2 + (Y-k)**2 - r**2 # equals to 0

plt.imshow(Fxy)
Out[5]:
<matplotlib.image.AxesImage at 0x115e0b7f0>
In [6]:
plt.contour(Fxy)
Out[6]:
<matplotlib.contour.QuadContourSet at 0x115d01978>
In [7]:
plt.contour(Fxy,0)
Out[7]:
<matplotlib.contour.QuadContourSet at 0x115fd0588>
In [8]:
plt.contour(X,Y,Fxy,0)
plt.plot([-axlim,axlim],[0,0],'k--')
plt.plot([0,0],[-axlim,axlim],'k--')
plt.plot(h,k,'go')

plt.gca().set_aspect('equal')
plt.show()

Exercise

In [9]:
h = [-1.5,1.5]

x = np.linspace(-5,5,100)
X,Y = np.meshgrid(x,x)

for r in np.linspace(.5,3,15):
    for hi in h:
        Fxy = (X-hi)**2 + (Y-0)**2 - r**2
        plt.contour(X,Y,Fxy,0,colors=[[r/3,r/3,r/3]])
        
        
plt.axis('off')
plt.gca().set_aspect('equal')
plt.plot(h,[0,0],'k',linewidth=3)
plt.show()