0% found this document useful (0 votes)
5 views

Practical No.1

The document contains a Jupyter Notebook with various Python code snippets for plotting different mathematical functions and data visualizations using libraries like NumPy and Matplotlib. It includes plots for functions such as sine, cosine, exponential, logarithmic, and linear functions, as well as bar graphs, pie charts, and histograms. Each section demonstrates the use of plotting techniques, labeling, and legends for better data representation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Practical No.1

The document contains a Jupyter Notebook with various Python code snippets for plotting different mathematical functions and data visualizations using libraries like NumPy and Matplotlib. It includes plots for functions such as sine, cosine, exponential, logarithmic, and linear functions, as well as bar graphs, pie charts, and histograms. Each section demonstrates the use of plotting techniques, labeling, and legends for better data representation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

Q.1

In [1]:

from pylab import*


import numpy as np
x=np.linspace(-1,1,100)
f=x**3
g=x**4
plot(x,f)
plot(x,g)
show()

Q.2

localhost:8888/notebooks/Untitled15.ipynb# 1/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [2]:

from pylab import*


import numpy as np
x=np.linspace(1,10,10)
y = np.log10(x)
plot(x,y,"--or",label="$y=log_{10}x$")
xlabel('x')
ylabel('y')
title('Graph of $y=log_{10}x$')
legend()
show()

Q. 3

localhost:8888/notebooks/Untitled15.ipynb# 2/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [3]:

from pylab import*


import numpy as np
from math import*
x=np.linspace(0,5,100)
y1=np.sin(x)
y2=np.cos(x)
y3=np.exp(x)
y4=x**2
subplot(2,2,1)
plot(x,y1,label="$\sin x$")
legend()
subplot(2,2,2)
plot(x,y2,label="$\cos x$")
legend()
subplot(2,2,3)
plot(x,y3,label="$e^x$")
legend()
subplot(2,2,4)
plot(x,y4,label="$x^2$")
legend()
show()

Q.4

localhost:8888/notebooks/Untitled15.ipynb# 3/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [6]:

from pylab import*


import numpy as np
from math import*
x=np.linspace(-5,5,100)
y=np.exp(-x)
plot(x,y,"-.^g",label="$y=e^{-x}$")
xlabel('x')
ylabel('y')
title('Graph of $y=e^{-x}$')
legend()
show()

Q.5

localhost:8888/notebooks/Untitled15.ipynb# 4/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [12]:

from pylab import*


import numpy as np
from math import*
x=np.linspace(1,10,100)
y1=np.log(x)+5
y2=np.log(x)-5
plot(x,y1,"r",lw=1.5)
plot(x,y2,"b",lw=2.5)
legend()
show()

No artists with labels found to put in legend. Note that artists whose la
bel start with an underscore are ignored when legend() is called with no a
rgument.

Q.6

localhost:8888/notebooks/Untitled15.ipynb# 5/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [13]:

from pylab import*


import numpy as np
from math import*
x=np.linspace(-5,5,100)
y=x
plot(x,y,label="$y=x$")
xlabel('x')
ylabel('y')
title('Graph of $y=x$')
legend(loc=2)
show()

Q.7

localhost:8888/notebooks/Untitled15.ipynb# 6/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [15]:

from pylab import*


import numpy as np
from math import*
x=[1,2,3]
y1=[3,6,2]
plot(x,y1,label='line1')
y2=[7,2,5]
plot(x,y2,label='line2')
xlabel('x')
ylabel('y')
title('Two lines on the same graph')
legend()
show()

Q.8

localhost:8888/notebooks/Untitled15.ipynb# 7/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [9]:

import numpy as np
import matplotlib.pyplot as plt
x=['Pune','Mumbai','Nagpur','Nasik','Satara']
y=[5,24,45,32,15]
plt.bar(x,y)
plt.xlabel('cities')
plt.ylabel('Number of covid patients')
plt.title('Bar graph')
plt.legend()
plt.show()

No artists with labels found to put in legend. Note that artists whose la
bel start with an underscore are ignored when legend() is called with no a
rgument.

Q.9

localhost:8888/notebooks/Untitled15.ipynb# 8/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [15]:

import numpy as np
import matplotlib.pyplot as plt
x=[1,2,3,4,5]
y=[5,24,45,32,15]
tick_label=['Pune','Mumbai','Nagpur','Nasik','Satara']
fig=plt.figure(figsize=(10,7))
plt.pie(y,labels=tick_label)
plt.show()

Q.10

localhost:8888/notebooks/Untitled15.ipynb# 9/10
4/8/23, 4:45 PM Untitled15 - Jupyter Notebook

In [22]:

import numpy as np
import matplotlib.pyplot as plt
ages=[2,5,79,89,79,30,45,52,50,29,30,30,50,90,45,48,65,99]
bins=5
plt.hist(ages,bins,range=(0,100))
plt.xlabel('ages')
plt.ylabel('Number of people')
plt.title('Histogram')
plt.legend()
plt.show()

No artists with labels found to put in legend. Note that artists whose la
bel start with an underscore are ignored when legend() is called with no a
rgument.

localhost:8888/notebooks/Untitled15.ipynb# 10/10

You might also like