import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
x = np.arange(0,20,0.1) #numpy helps us to create an ordered AP array using arange function
print(x)
[ 0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3. 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4. 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5. 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6. 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7. 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8. 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9. 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10. 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11. 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 12. 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 13. 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 14. 14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8 14.9 15. 15.1 15.2 15.3 15.4 15.5 15.6 15.7 15.8 15.9 16. 16.1 16.2 16.3 16.4 16.5 16.6 16.7 16.8 16.9 17. 17.1 17.2 17.3 17.4 17.5 17.6 17.7 17.8 17.9 18. 18.1 18.2 18.3 18.4 18.5 18.6 18.7 18.8 18.9 19. 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 19.9]
y = np.cos(x)
print(y)
[ 1. 0.99500417 0.98006658 0.95533649 0.92106099 0.87758256 0.82533561 0.76484219 0.69670671 0.62160997 0.54030231 0.45359612 0.36235775 0.26749883 0.16996714 0.0707372 -0.02919952 -0.12884449 -0.22720209 -0.32328957 -0.41614684 -0.5048461 -0.58850112 -0.66627602 -0.73739372 -0.80114362 -0.85688875 -0.90407214 -0.94222234 -0.97095817 -0.9899925 -0.99913515 -0.99829478 -0.98747977 -0.96679819 -0.93645669 -0.89675842 -0.84810003 -0.79096771 -0.7259323 -0.65364362 -0.57482395 -0.49026082 -0.40079917 -0.30733287 -0.2107958 -0.11215253 -0.01238866 0.08749898 0.18651237 0.28366219 0.37797774 0.46851667 0.55437434 0.63469288 0.70866977 0.77556588 0.83471278 0.88551952 0.92747843 0.96017029 0.98326844 0.9965421 0.99985864 0.99318492 0.97658763 0.95023259 0.91438315 0.86939749 0.8157251 0.75390225 0.68454667 0.60835131 0.52607752 0.43854733 0.34663532 0.25125984 0.15337386 0.05395542 -0.04600213 -0.14550003 -0.24354415 -0.33915486 -0.43137684 -0.51928865 -0.6020119 -0.67872005 -0.74864665 -0.81109301 -0.86543521 -0.91113026 -0.9477216 -0.97484362 -0.99222533 -0.99969304 -0.99717216 -0.98468786 -0.96236488 -0.93042627 -0.88919115 -0.83907153 -0.78056818 -0.71426565 -0.64082642 -0.56098426 -0.47553693 -0.38533819 -0.29128928 -0.19432991 -0.09542885 0.0044257 0.10423603 0.20300486 0.29974534 0.39349087 0.48330476 0.56828963 0.64759634 0.72043248 0.7860703 0.84385396 0.89320611 0.93363364 0.96473262 0.9861923 0.99779828 0.99943459 0.99108487 0.97283257 0.94486004 0.90744678 0.86096662 0.80588396 0.74274917 0.67219308 0.59492066 0.51170399 0.42337454 0.33081488 0.23494982 0.13673722 0.03715838 -0.06279172 -0.16211444 -0.25981736 -0.35492427 -0.44648489 -0.53358439 -0.61535248 -0.69097218 -0.75968791 -0.82081309 -0.87373698 -0.91793078 -0.95295292 -0.97845346 -0.99417763 -0.99996829 -0.99576761 -0.98161754 -0.95765948 -0.9241328 -0.88137249 -0.8298058 -0.76994796 -0.70239706 -0.62782804 -0.54698596 -0.46067859 -0.36976826 -0.27516334 -0.17780907 -0.07867819 0.02123881 0.1209436 0.21943996 0.31574375 0.40889274 0.4979562 0.58204425 0.66031671 0.7319915 0.79635247 0.85275655 0.90064017 0.93952489 0.96902219 0.98883734 0.99877236 0.99872797 0.98870462 0.96880246 0.93922035 0.90025385 0.85229232 0.79581497 0.7313861 0.65964945 0.58132181 0.49718579]
plt.plot(x,y)
plt.show()
#many times we want to plot more than one curves in the same graph how do we do it?
y1=np.exp(x/10)*np.cos(x)
plt.plot(x,y)
plt.plot(x,y1)
plt.show()
#which curve represent which arrar? to do that we can label them
plt.plot(x,y, label="oscillation 1")
plt.plot(x,y1, label="oscillation 2")
plt.legend() #this will make the labels to appeare
plt.show()
#now lets nam x and y axises
plt.plot(x,y, label="oscillation 1")
plt.plot(x,y1, label="oscillation 2")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.legend()
plt.show()
#one of the cool tool of matplotlib is we can use direct latex formulae in it
plt.plot(x,y, label="oscillation 1",linewidth=3) #this will thicken the curve
plt.plot(x,y1, label="oscillation 2",color="r",linestyle="--")#i want to change the color and i changed the line style
plt.xlabel("X-axis", size=24)
plt.ylabel("$\sin(x)$",size=24)
plt.legend()
plt.show()
#we have so many other features in the matplotlib which we can go in this lecture. we can find them on the internet regarding matplotlib in matplotlib.org