Plot a graph using Python plot the graph of f(x)=sin(x) and g(x)=cos(x) in [-2*pi, 2*pi]
Plot the graph of f(x)=sin(x) and g(x)=cos(x) in [-2*pi, 2*pi]
In this program, we are polt a graph using python
The Program is divide into 3 step
Step1:-- import python package using
from pylab import *
import numpy as np
Step2:- assign the value of x and function
x = np.linspace(-2*np.pi, 2 * np.pi, 200)
f = np.sin(x)
g = np.cos(x)
Step3 :- Plot the graph and show it using plot() , show() function
# plotting method
# method-1
# plot(x, f, g)
# method-2
plot(x, f)
plot(x, g)
show()
Complete program
# plot the graph of f(x)=sin(x) and g(x)=cos(x) in [-2*pi, 2*pi]
from pylab import *
import numpy as np
x = np.linspace(-2*np.pi, 2 * np.pi, 200)
f = np.sin(x)
g = np.cos(x)
# plotting method
# method-1
# plot(x, f, g)
# method-2
plot(x, f)
plot(x, g)
show()
Output
Plot a graph and give a label using
Step1:-- import python package using
from pylab import *
import numpy as np
Step2:- assign the value of x and function
x = np.linspace(-2*np.pi, 2 * np.pi, 200)
f = np.sin(x)
g = np.cos(x)
Step3 :- give a label using label function Plot the graph and show it using plot() , show()
plot(x, f, label="sin(x)")
plot(x, g, label="cos(x)")
# give a title
title("This is 2d graph ")
# give X label
xlabel("This is x")
# # give Y label
ylabel("This is y")
show()
Complete program
# plot the graph of f(x)=sin(x) and g(x)=cos(x) in [-2*pi, 2*pi]
from pylab import *
import numpy as np
x = np.linspace(-2*np.pi, 2 * np.pi, 200)
f = np.sin(x)
g = np.cos(x)
# plotting method
# method-1
# plot(x, f, g)
# method-2
plot(x, f, )
plot(x, g,)
# Plot a graph and give a label using
plot(x, f, label="sin(x)")
plot(x, g, label="cos(x)")
# give a title
title("This is 2d graph ")
# give X label
xlabel("This is x")
# # give Y label
ylabel("This is y")
show()
Output
0 Comments