Practical 1
Practical 1
1)
x = np.linspace(0,10)
y = np.log10(x)
plt.plot(x,y)
plt.show()
C:\Users\MMC\AppData\Local\Temp\ipykernel_3992\1439288947.py:8: RuntimeWarning: di
vide by zero encountered in log10
y = np.log10(x)
Ex. To Plot the functions f(x) = log_10 (x) on the interval [0,2π] . Refer to the code
below
x = np.arange(-1, 1, 0.01)
y = np.arcsin(x)
plt.plot(x,y)
plt.show()
x = np.linspace(-2, 2, 100)
y = x**2
x = np.linspace(-1, 2, 100)
y = np.exp(x)
plt.plot(x,y)
plt.show()
plt.plot(x,y)
plt.show()
C:\Users\MMC\AppData\Local\Temp\ipykernel_5700\2469820470.py:5: RuntimeWarning: di
vide by zero encountered in log10
y = np.sin(x)-np.exp(x)+3*x**2+np.log10(x)
plt.style.use('seaborn-white')
def f(x, y):
return np.sin(x) **10 + np.cos(5 + x*y) * np.sin(x)
x = np.linspace(0, 5, 50)
y = np.linspace(0, 5, 50)
X, Y = np.meshgrid(x,y)
Z = f(x,Y)
C:\Users\MMC\AppData\Local\Temp\ipykernel_5700\2431292763.py:9: MatplotlibDeprecat
ionWarning: The seaborn styles shipped by Matplotlib are deprecated since 3.6, as
they no longer correspond to the styles shipped by seaborn. However, they will rem
ain available as 'seaborn-v0_8-<style>'. Alternatively, directly use the seaborn A
PI instead.
plt.style.use('seaborn-white')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[13], line 19
16 Z = f(x,Y)
18 plt.contourf(X, Y, Z, 10, cmap = 'RdBu')
---> 19 plt.colourbar()
x2 = [1, 2, 3]
y2 = [7, 2, 5]
plt.plot(x2, y2, label = "line 2")
plt.xlabel('x-axis')
plt.ylabel('y-axis')
left = [1, 2, 3, 4, 5]
height = [5, 24, 45, 32, 15]
plt.title('Covid-19 Data')
plt.show()
1.3.3: Histogram
In [4]: import numpy as np
import matplotlib.pyplot as plt
ages = [2, 3, 70, 40, 30, 45, 50, 45, 43, 40, 44, 60, 7, 13, 57, 57, 18, 90, 77, 32
range = (0, 100)
bins = 5
plt.xlabel('Age')
plt.ylabel('No. Of People')
plt.title('Histogram Plot')
plt.show()
left = [1,2,3,4,5]
height = [5,24,45,32,15]
plt.show()
girls_score = [81, 90, 70, 89, 100, 80, 90, 100, 80, 34]
boys_score = [30, 29, 49, 48, 100, 48, 34, 45, 20, 30]
grades_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
fig = plt.figure()
ax=fig.add_axes([0,0,1,1])
plt.show()