How to plot a circle in python

 How to plot a circle in python

import matplotlib.pyplot as plt 
import numpy as np
t  =np.linspace(0,360,500) # t is angle here changing the value of 360 you can control the arc of circle
r = 30  # r is radius
x = r *np.sin(np.radians(t))
y = r*np.cos(np.radians(t))
plt.plot(x,y)
plt.axis('equal')  # if you don't add this line it will make you graph look like ellipse if you add it will look like circle the purpose of this line is to make axis equal on both sides


Making interactive Circle in python 

import matplotlib.pyplot as plt
import numpy as np
from ipywidgets import interactive
def f(r,theta):
    t  =np.linspace(0,theta,500) # t is angle here changing the value of 360 you can control the arc of circle
    r = 30  # r is radius
    x = r *np.sin(np.radians(t))
    y = r*np.cos(np.radians(t))
    plt.plot(x,y)
    plt.axis('equal')
interactive_plots = interactive(f ,r =(0.1,10),theta = (0,360))
interactive_plots









Post a Comment

0 Comments