22import matplotlib .pyplot as plt
33import numpy as np
44# function to draw a circle
5+ center = tuple (map (float , input ("Enter the center coordinates as x,y: " ).split (',' )))
6+ radius = float (input ("Enter the radius of the circle: " ))
57def draw_circle (ax , center , radius , color ):
68 circle = plt .Circle (center , radius , color = color , fill = False , linewidth = 1 )
79 ax .add_artist (circle )
@@ -11,20 +13,20 @@ def draw_circle(ax, center, radius, color):
1113# set aspect of the plot to be equal
1214ax .set_aspect ('equal' )
1315# set limits
14- ax .set_xlim (- 5 , 5 )
15- ax .set_ylim (- 5 , 5 )
16- # draw circles
17- draw_circle (ax , ( 0 , 0 ), 4 , 'blue' )
16+ ax .set_xlim (- 10 , 10 )
17+ ax .set_ylim (- 10 , 10 )
18+ # draw circle with user input
19+ draw_circle (ax , center , radius , 'blue' )
1820# add labels and title
1921ax .set_xlabel ('X-axis' )
2022ax .set_ylabel ('Y-axis' )
21- ax .plot (0 , 0 , 'ro' ) # mark center
23+ ax .plot (center [ 0 ], center [ 1 ] , 'ro' ) # mark center
2224# add grid and highlight X and Y axes
2325ax .axhline (0 , color = 'yellow' ,linewidth = 0.5 , ls = '--' )
2426ax .axvline (0 , color = 'yellow' ,linewidth = 0.5 , ls = '--' )
2527ax .grid (color = 'gray' , linestyle = '--' , linewidth = 0.5 )
2628#add title
27- plt .title ('Circle with radius 4 centered at (0,0) ' )
29+ plt .title (f 'Circle with radius { radius } centered at { center } ' )
2830plt .show ()
2931# save the plot
3032plt .savefig ('circle_plot.png' )
0 commit comments