-2

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.

JohanC
  • 71,591
  • 8
  • 33
  • 66
  • There seem to be multible functions to plot circles with for example matplotlib. As I do not know the context of your questions here the link to different methods: https://www.pythonpool.com/matplotlib-circle/ – Sam Oct 27 '21 at 06:15

2 Answers2

2

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))

sympy plot_implicit

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))
JohanC
  • 71,591
  • 8
  • 33
  • 66
0

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)
Kota Mori
  • 6,510
  • 1
  • 21
  • 25