-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlottingBasicEquations.py
More file actions
36 lines (35 loc) · 939 Bytes
/
PlottingBasicEquations.py
File metadata and controls
36 lines (35 loc) · 939 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
33
34
35
import matplotlib.pyplot as plt
import numpy as np
# function to generate coordinates
def create_plot(ptype):
# setting the x-axis vaues
x = np.arange(-10, 10, 0.1)
if ptype == 'linear':
y = x
elif ptype == 'quadratic':
y = x**2
elif ptype == 'cubic':
y = x**3
elif ptype == 'quartic':
y = x**4
return(x, y)
plt.style.use('fivethirtyeight')
fig = plt.figure()
plt1 = fig.add_subplot(221)
plt2 = fig.add_subplot(222)
plt3 = fig.add_subplot(223)
plt4 = fig.add_subplot(224)
x, y = create_plot('linear')
plt1.plot(x, y, color ='r')
plt1.set_title('$y_1 = x$')
x, y = create_plot('quadratic')
plt2.plot(x, y, color ='b')
plt2.set_title('$y_2 = x^2$')
x, y = create_plot('cubic')
plt3.plot(x, y, color ='g')
plt3.set_title('$y_3 = x^3$')
x, y = create_plot('quartic')
plt4.plot(x, y, color ='k')
plt4.set_title('$y_4 = x^4$')
fig.subplots_adjust(hspace=.5,wspace=0.5)
plt.show()