9/10/81, 2:35 AM Practical 1 - Jupyter Notebook
1 Practical 1 (2D plots Using Python)
2 Name:- Advait Trimbake
3 RollNo.:- 253332131
4 Div:- B
5 Date:-21/07/2025
In [9]: 1 #Q1.Using python draw a bar garph to represent the data below.
2 from matplotlib.pyplot import *
3 x=['maths','Sci','eng','marathi','hindi']
4 y=[80,69,72,58,90]
5 bar(x,y,color='g')
6 xlabel('subject')
7 ylabel('marks')
8 title('Bar Graph')
9 show()
localhost:8888/notebooks/Practical 1.ipynb 1/7
9/10/81, 2:35 AM Practical 1 - Jupyter Notebook
In [8]: 1 #Q2.Using python draw a Horizontal bar garph to represent the data belo
2 from matplotlib.pyplot import *
3 x=['maths','Sci','eng','marathi','hindi']
4 y=[80,69,72,58,90]
5 barh(x,y,color=['g','r','b','y','k'])
6 xlabel('subject')
7 ylabel('marks')
8 title('Horizontal Bar Graph')
9 show()
In [12]: 1 #Q3.Using python draw a pie graph for the data given in Q1.
2 x=['maths','Sci','eng','marathi','hindi']
3 y=[80,69,72,90,70]
4 pie(y,labels=x)
5 xlabel('Subjects')
6 ylabel('Marks')
7 title('Pie Chart')
8 legend()
9 show()
localhost:8888/notebooks/Practical 1.ipynb 2/7
9/10/81, 2:35 AM Practical 1 - Jupyter Notebook
In [15]: 1 #Q4.Using python draw the histogram graph for the following data with 5
2 x=[21,22,23,4,5,6,77,8,9,10,31,32,33,34,35,36,37,18,49,50,100]
3 num_bins=5
4 hist(x,num_bins,facecolor='blue' ,alpha=0.5)
5 show()
In [24]: 1 #Q5.Using python draw the Scatter plot for the data given in Q4.
2 from numpy import *
3 y=[21,22,23,4,5,6,77,8,9,10,31,32,33,34,35,36,37,18,49,50,100]
4 x=random.randint(1,100,21)
5 scatter(x,y,color="black",marker='p')
6 title('Scatter Graph')
7 xlabel('x axis')
8 ylabel('y axis')
9 show()
localhost:8888/notebooks/Practical 1.ipynb 3/7
9/10/81, 2:35 AM Practical 1 - Jupyter Notebook
In [27]: 1 #Q6.Write a python program to plot 2D garaph of the following functions
2 # i.
3 from math import *
4 import numpy as np
5 x=np.linspace(1,10)
6 y=np.log(x)
7 plot(x,y)
8 show()
In [28]: 1 #ii.
2 x=np.linspace(-2*pi,2*pi)
3 y=np.cos(x)
4 plot(x,y)
5 show()
localhost:8888/notebooks/Practical 1.ipynb 4/7
9/10/81, 2:35 AM Practical 1 - Jupyter Notebook
In [32]: 1 #iii.
2 x=np.linspace(-7,2)
3 y=np.exp(x)
4 plot(x,y)
5 show()
In [33]: 1 #iv.
2 x=np.linspace(-1,1)
3 y=np.arcsin(x)
4 plot(x,y)
5 show()
localhost:8888/notebooks/Practical 1.ipynb 5/7
9/10/81, 2:35 AM Practical 1 - Jupyter Notebook
In [44]: 1 #Q7.
2 #a.Write a python program to plot 2D Graph of following function f(x^2)
3 def f(x):
4 return(x**2)
5 def g(x):
6 return(x**3)
7 x=np.linspace(-1,1,50)
8 plot(x,f(x),'y',label='X^2')
9 plot(x,g(x),'k',label='X^3')
10 legend()
11 show()
In [50]: 1 #b.Write a python program to plot 2D Graph of the function f(x^4) in [0
2 # circle markers.
3 def f(x):
4 return(x**4)
5 x=np.linspace(0,5,8)
6 plot(x,f(x),'r',linestyle='--',marker='v',mfc='g',markersize=8)
7 show()
localhost:8888/notebooks/Practical 1.ipynb 6/7
9/10/81, 2:35 AM Practical 1 - Jupyter Notebook
In [54]: 1 #Q8.Write a python program to generate plot of function f(x^2) in the i
2 def f(x):
3 return(x**2)
4 x=np.linspace(-5,5)
5 plot(x,f(x),'r',label='X^2')
6 figure(figsize=(6,6))
7 show()
<Figure size 432x432 with 0 Axes>
localhost:8888/notebooks/Practical 1.ipynb 7/7