File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Plot parabolas of the form x^2 = 4ay by user-defined "a", a!=0
2+ import numpy as np
3+ import matplotlib .pyplot as plt
4+ # Function to plot Parabola
5+ a = float (input ("Enter the value of a: " ))
6+ def plot_parabola (a , ax ):
7+ x = np .linspace (- 10 , 10 , 400 )
8+ y = (x ** 2 ) / (4 * a )
9+ ax .plot (x , y , 'r' , label = f'Parabola: x^2 = 4*{ a } *y' )
10+ # Create figure and axis
11+ fig , ax = plt .subplots ()
12+ # Set aspect of the plot to be equal
13+ ax .set_aspect ('equal' )
14+ # Set limits
15+ ax .set_xlim (- 10 , 10 )
16+ ax .set_ylim (- 10 , 10 )
17+ # Plot parabola with a from user input
18+ plot_parabola (a , ax )
19+ # Add labels and title
20+ ax .set_xlabel ('X-axis' )
21+ ax .set_ylabel ('Y-axis' )
22+ plt .title (f'Parabola: x^2 = 4*{ a } *y' )
23+ # Add grid and highlight X and Y axes
24+ ax .grid (True )
25+ ax .axhline (0 , color = 'black' , linewidth = 0.5 )
26+ ax .axvline (0 , color = 'black' , linewidth = 0.5 )
27+ plt .show ()
28+ # Save the plot
29+ plt .savefig ('parabola1_plot.png' )
You can’t perform that action at this time.
0 commit comments