-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Plot_Graph.py
61 lines (47 loc) · 1.29 KB
/
Plot_Graph.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import matplotlib.pyplot as plt
import math as mt
import random as rand
# X and Y axis co-ordinates
xx = []
yy = []
# Function to be ploted i.e the value of y
f = lambda x : 2*x*x+5*x+3
# Diffrent function to try from
#f = lambda x : x
#f = lambda x : pow(x,2)
#f = lambda x : pow(x,3)
#f = lambda x : pow(x,4)
#f = lambda x : abs(x)
#f = lambda x : mt.sin(x)
#f = lambda x : mt.cos(x)
#f = lambda x : mt.tan(x)
#f = lambda x : rand.randint(0,100)
#f = lambda x : mt.sqrt(x)
#f = lambda x: 1/x
'''
NOTE: While choosing the function, Do check whether the range of limit is within
the domain of the function.
For example:- f(x)=1/x
Here 0 is not in the domain of the function,
Hence try to modify the for loop with one or more conditional statements
accordingly.
'''
# Number of Y co-ordinates
limit = 50
# Calculation the X co-ordinated using the function declared above
for i in range(-limit, limit):
# if i==0:
# continue
xx.append(i)
yy.append(f(i))
# plotting the points
plt.plot(xx, yy, linewidth=1)
plt.grid(color='black', linestyle='-', linewidth=0.30)
# Labeling the x axis
plt.xlabel('x - axis')
# Labeling the y axis
plt.ylabel('y - axis')
# giving a title to my graph
plt.title('Graph for the function :')
# function to show the plot
plt.show()