-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
32 lines (24 loc) · 692 Bytes
/
Copy pathplot.py
File metadata and controls
32 lines (24 loc) · 692 Bytes
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
# Created by: Brian Shortiss
# Created on: 25 March 2020
# 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.
# Sources:
# https://realpython.com/how-to-use-numpy-arange/
# https://gist.github.com/aunyks/44648b839e7c59b47afecca62c9a88de
import numpy as np
import matplotlib.pyplot as plt
# Create functions
x = np.arange(0, 4) # Start, Stop
f = x
g = x**2
h = x**3
# Plot functions
plt.plot(f, 'r')
plt.plot(g, 'b')
plt.plot(h, 'g')
# Plot configuration
plt.legend(['f(x)=x', 'g(x)=x2', 'h(x)=x3'], loc='upper left')
plt.grid()
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.title('Function Plot')
plt.show()