Skip to content

Commit 2a8dd26

Browse files
committed
x^2=4ay parabola plot code
1 parent 4560288 commit 2a8dd26

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

parabola1_plot.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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')

0 commit comments

Comments
 (0)