-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_parabola.py
43 lines (30 loc) · 882 Bytes
/
plot_parabola.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# plot_parabola.py
import matplotlib.pyplot as plt
import numpy as np
def plot(ax):
x = np.linspace(-4, 5, 100)
y = np.power(x,2) + 1
# Step 1 - Plot the graph on the main axes
ax.plot(x, y)
# Step 2 - Give the graph a title and axis labels
ax.set_title("$y = x^2+1$") # LaTeX format
ax.set_xlabel("x")
ax.set_ylabel("y")
# Step 3 - Center the graph on appropriate range
ax.set_xlim(-6, 6)
ax.set_ylim(-3, 30)
# Step 4 - Turn on the grid, and add decorations
ax.grid()
ax.axhline(0, color='black')
ax.axvline(0, color='black')
ax.plot(0, 1, color='red', marker='o')
ax.axhline(1, color='blue', linestyle='--')
def main():
fig = plt.figure()
gs = fig.add_gridspec(1, 1)
ax = fig.add_subplot(gs[0, 0])
plot(ax)
plt.show()
if __name__ == "__main__":
main()