forked from Anjan50/Python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPython code for plotting curve
More file actions
73 lines (60 loc) · 2.06 KB
/
Python code for plotting curve
File metadata and controls
73 lines (60 loc) · 2.06 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
# Importing Required Libraries
import numpy as np
import matplotlib.pyplot as plt
import csv
# Generating time data using arange function from numpy
time = np.arange(-3*np.pi, 3*np.pi, 0.01)
amplitude1 = np.sin(time)
amplitude2 = np.cos(time)
#adding values of amplitude1 amplitude2 and time in a array amplitude
amplitude = np.array([[amplitude1],[time],[amplitude2]])
def csvfile():
#converting into csv file
amplitude.tofile('amplitude.csv',sep=' ',format='%10f')
#print(amplitude)
with open('amplitude.csv','r') as file:
reader =csv.reader(file)
for row in reader:
print(row)
def sineCurve():
#Plotting time vs amplitude using plot function from pyplot
plt.plot(time, amplitude1)
# Settng title for the plot in red color for sine wave
plt.title('sine Wave graph in python', color='r')
# Setting x axis label for the plot
plt.xlabel('Time'+ r'$\rightarrow$')
# Setting y axis label for the plot
plt.ylabel('Sine(time) '+ r'$\rightarrow$')
# Showing grid
plt.grid()
# Highlighting axis at x=0 and y=0
plt.axhline(y=0, color='k')
plt.axvline(x=0, color='k')
#saving the output
plt.savefig('sine.png',dpi=300,bbox_inches='tight')
# Finally displaying the plot
plt.show()
def CosineCurve():
# Plotting time vs amplitude using plot function from pyplot
plt.plot(time, amplitude2)
# Settng title for the plot in red color for Cosine wave
plt.title('Cosine Wave graph in python', color='r')
# Setting x axis label for the plot
plt.xlabel('Time'+ r'$\rightarrow$')
# Setting y axis label for the plot
plt.ylabel('Cosine(time) '+ r'$\rightarrow$')
# Showing grid
plt.grid()
# Highlighting axis at x=0 and y=0
plt.axhline(y=0, color='k')
plt.axvline(x=0, color='k')
#saving the output
plt.savefig('Cosine.png',dpi=300,bbox_inches='tight')
# # Finally displaying the plot
plt.show()
#function defined for sine wave
sineCurve()
#function defined for cosine wave
CosineCurve()
#function for csv file
csvfile()