How can I plot x^2 + y^2 = 9 as a circle not 3d equation in python
I cannot find any where to plot equality equation in python. Can you please help me out in this.
How can I plot x^2 + y^2 = 9 as a circle not 3d equation in python
I cannot find any where to plot equality equation in python. Can you please help me out in this.
You can use sympy as follows:
from sympy import Eq, plot_implicit
from sympy.abc import x, y
plot_implicit(Eq(x ** 2 + y ** 2, 9), aspect_ratio=(1, 1))
There is also plot_parametric
:
from sympy import plot_parametric, cos, sin, pi
from sympy.abc import t
plot_parametric(cos(t), sin(t), (t, 0, 2 * pi), aspect_ratio=(1, 1))
You can derive x,y by solving the equation.
For example, noting that -3 <= x <= 3
and y = +- sqrt(9-x^2)
,
import numpy as np
x = np.linspace(-3, 3)
y = np.sqrt(9-x)
import matplotlib.pyplot as plt
plt.scatter(x, y)
plt.scatter(x, -y)
Alternatively, since this relation can be expressed by the polar coordinate 0 <= theta < 2*pi
with x = 3 cos(theta), y = 3 sin(theta),
theta = np.linspace(0, 2*np.pi)
x = 3*np.cos(theta)
y = 3*np.sin(theta)
plt.scatter(x, y)