Trignometry Visualisation In Jupyter notebook Python

 Trignometry Visualisation In Jupyter notebook Python


In this blog, we are going to learn how to visualize trigonometry functions
[Please give valuable feedback what you don't like this blog so that it can update and more readable]



First we are going to import numpy , matplotlib and ipywidget  for mathematical calculation,graph plotting and making slider in jupyter notebook respectively

then we will define a funciton f which contain two parameter r and t (radius and theta)
then we have defined our figsize (4,8)





Since we are going to plot two graph then we are going to use subplot
in subplot you will see (211) it means that we have 2 graph 1 colum and 1st row .This basically tells our first subplot graph location 
in case of (212) it means that we have 2 graph 1 colum and 2nd row .This basically tells our first subplot graph location 
then th basically it is going to use for plotting our circle for more information please watch this video 
x and y variable are base triangle and height of triangle length respectively
Then I plot a circle graph and triangle on the same graph

in next subplot i basically define a simple sin graph 
here you notice this code 
theta = np.linspace(0,t,360)
it means that sin graph start from 0 and end to t (define by slider) , here 360 represent 360 points between 0 and t
Then  s = r*np.sin(np.radians(theta))
here you notice radians by convention whatever value you give to python it give output as radians but we want in degrees for that reason we have np.radians(i know you think its opposite need to be write but this is how it works)
After that i plot both these graph




import matplotlib.pyplot as plt
import numpy as np
from ipywidgets import interactive
def f(r,t):
    g = plt.figure(figsize=(4,8))
    ax = g.add_subplot(211)
    ax2 = g.add_subplot(212)
    th =np.linspace(0,360,360)
    x= r *np.sin(np.radians(t))
    y =r *np.cos(np.radians(t))
   
    a =([0,x,x,0])
    b =([0,0,y,0])
    c = r *np.sin(np.radians(th))
    d = r *np.cos(np.radians(th))  
    plt.xlabel('angle')
    ax.plot(a,b,c,d)
    
    
    theta = np.linspace(0,t,360)
    s = r*np.sin(np.radians(theta))
    ax2.plot(theta,s)
    
    #plt.axis('equal')
    plt.tight_layout()
    print("base length of triangle",x)
    print('height of the traingle',y)
    print('Hypotenuse of the traingel',np.sqrt(x**2+y**2))
interactive_plot = interactive(f,r=(5,30),t = (0,360))

interactive_plot



Post a Comment

0 Comments