Parametric and implicit plots¶
This notebook covers roughly the same ground as this video.
In [1]:
import numpy as np
import matplotlib.pyplot as plt
In [2]:
ts = np.linspace(0, 5, 1000)
xs = np.cos(10 * ts) / (1 + ts**2)
ys = np.sin(10 * ts) / (1 + ts**2)
plt.axis('equal')
plt.plot(xs, ys)
Out[2]:
[<matplotlib.lines.Line2D at 0x1f1af99e8d0>]
In [3]:
fig, ax = plt.subplots(1, 2)
fig.set_size_inches(10, 5)
ts = np.linspace(0, 2*np.pi, 1000)
ax[0].plot(np.sin(2*ts), np.sin(3*ts))
ax[1].plot(np.sin(6*ts), np.sin(7*ts))
Out[3]:
[<matplotlib.lines.Line2D at 0x1f1b1c7ecd0>]
In [5]:
ts = np.linspace(0, 8*np.pi, 1000)
xs = ts - np.sin(ts)
ys = 1 - np.cos(ts)
plt.axis('equal')
plt.plot(xs, ys)
plt.hlines(0, 0, 8*np.pi, color='gray', linestyle='--')
Out[5]:
<matplotlib.collections.LineCollection at 0x1f1af9b7810>
In [6]:
Out[6]:
[<matplotlib.lines.Line2D at 0x1f1afa6bd10>]
In [10]:
xr = np.linspace(-2, 2, 400)
yr = np.linspace(-2, 2, 400)
x, y = np.meshgrid(xr, yr)
plt.contour(x, y, y**2 - (x**3 - x), levels=[0], colors='red')
Out[10]:
<matplotlib.contour.QuadContourSet at 0x1f1b3d62990>
In [13]:
xr = np.linspace(-2, 2, 400)
yr = np.linspace(-2, 2, 400)
x, y = np.meshgrid(xr, yr)
plt.contour(x, y, y**2 - (x**3 - x), levels=[0.3,0.4], colors=['red','blue'])
Out[13]:
<matplotlib.contour.QuadContourSet at 0x1f1b71f2990>
In [21]:
xr = np.linspace(0.4, 0.8, 400)
yr = np.linspace(-0.3, 0.3, 400)
x, y = np.meshgrid(xr, yr)
plt.contour(x, y, y**2 - (x**3 - x), levels=[0.38,0.3848,0.389], colors=['red','green','blue'])
Out[21]:
<matplotlib.contour.QuadContourSet at 0x1f1ba57e190>
In [31]:
xr = np.linspace(-5, 5, 1000)
yr = np.linspace(-5, 5, 1000)
x, y = np.meshgrid(xr, yr)
r2 = x**2 + y**2
t = np.linspace(-5, 5, 1000)
fig, ax = plt.subplots(1, 2)
fig.set_size_inches(10, 5)
ax[0].axis('equal')
ax[1].axis('equal')
ax[0].contour(x, y, x * np.sin(r2) - y * np.cos(r2), levels=[0], colors=['red'])
ax[1].plot(t * np.cos(t**2), t * np.sin(t**2))
Out[31]:
[<matplotlib.lines.Line2D at 0x1f1c018d810>]
In [37]:
xr = np.linspace(-8, 12, 1000)
yr = np.linspace(-10, 10, 1000)
x, y = np.meshgrid(xr, yr)
u = (x**2+y**2)**2 + 85*(x**2+y**2) - 500 + 18*x*(3*y**2-x**2)
t = np.linspace(0, 2*np.pi, 1000)
xt = 6*np.cos(t) + 8*np.cos(t)**2 - 4
yt = 2*np.sin(t)*(3-4*np.cos(t))
fig, ax = plt.subplots(1, 2)
fig.set_size_inches(10, 5)
ax[0].contour(x, y, u, levels=[0], colors=['red'])
ax[1].plot(xt, yt)
ax[0].set_xlim(-8, 12)
ax[0].set_ylim(-10, 10)
ax[1].set_xlim(-8, 12)
ax[1].set_ylim(-10, 10)
Out[37]:
(-10.0, 10.0)
In [ ]: