An implicit function is $ f (x, y) = 0 $, which is difficult to transform into an explicit shape.
Yen $ x ^ 2 + y ^ 2-1 = 0 $ is a typical example.
It's not impossible to transform it, but it's not very smart when drawing graphs because it requires case classification.
In such cases, contour
is convenient.
python
import matplotlib.pyplot as plt
import numpy as np
delta = 0.025
xrange = np.arange(-2, 2, delta)
yrange = np.arange(-2, 2, delta)
X, Y = np.meshgrid(xrange,yrange)
#Axis settings
plt.axis([-2, 2, -2, 2])
plt.gca().set_aspect('equal', adjustable='box')
#drawing
Z=X**2+Y**2-1
plt.contour(X, Y, Z, [0])
plt.show()
Plt.contour (X, Y, Z, [0])
in the code draws contour lines with Z = 0.
If you specify [-1,0,1]
, contour lines will be added. It's smart.
It's pretty short, but I feel like I'm just painting $-\ epsilon <f (x, y) <\ epsilon $.
python
from sympy import *
x, y = symbols("x y")
Z=x**2+y**2-1
plot_implicit(Z, (x, -2, 2), (y, -2, 2))
Recommended Posts