Skip to content

Commit 6055b3e

Browse files
committed
Added plot.py
1 parent 62fac8b commit 6055b3e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎plot.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Created by: Brian Shortiss
2+
# Created on: 25 March 2020
3+
4+
# Write a program that displays a plot of the functions f(x)=x, g(x)=x2 and h(x)=x3 in the range [0, 4] on the one set of axes.
5+
6+
# Sources:
7+
# https://realpython.com/how-to-use-numpy-arange/
8+
# https://gist.github.com/aunyks/44648b839e7c59b47afecca62c9a88de
9+
10+
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
14+
# Create functions
15+
x = np.arange(0, 4) # Start, Stop
16+
17+
f = x
18+
g = x**2
19+
h = x**3
20+
21+
# Plot functions
22+
plt.plot(f, 'r')
23+
plt.plot(g, 'b')
24+
plt.plot(h, 'g')
25+
26+
# Plot configuration
27+
plt.legend(['f(x)=x', 'g(x)=x2', 'h(x)=x3'], loc='upper left')
28+
plt.grid()
29+
plt.xlabel('X Axis')
30+
plt.ylabel('Y Axis')
31+
plt.title('Function Plot')
32+
plt.show()

0 commit comments

Comments
 (0)