0% found this document useful (0 votes)
21 views5 pages

Untitled3.ipynb (Auto-B - 5) - JupyterLab

The document contains Python code that uses Matplotlib and NumPy to plot various mathematical functions, including linear, quadratic, exponential, and trigonometric functions. It demonstrates the plotting of functions like f(x) = 3x-4, f(x) = x^2 + 2x - 15, and f(x) = e^x, as well as sine, cosine, tangent, and cotangent functions over specified ranges. An error occurs due to a typo in the plotting function, where 'plt.sow()' should be 'plt.show()'.

Uploaded by

neeru.kum22
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)
21 views5 pages

Untitled3.ipynb (Auto-B - 5) - JupyterLab

The document contains Python code that uses Matplotlib and NumPy to plot various mathematical functions, including linear, quadratic, exponential, and trigonometric functions. It demonstrates the plotting of functions like f(x) = 3x-4, f(x) = x^2 + 2x - 15, and f(x) = e^x, as well as sine, cosine, tangent, and cotangent functions over specified ranges. An error occurs due to a typo in the plotting function, where 'plt.sow()' should be 'plt.show()'.

Uploaded by

neeru.kum22
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/ 5

In [7]: import matplotlib.

pyplot as plt
import numpy as np
#define x range
x = np.arange(1,21)

f1 = 3*x - 4
f2 = x**2 +2*x -15
f3 = 5*(x-1)*(x-2)*(x-3)
f4 = np.exp(x)
#plot each function
plt.figure(figsize=(12,10))

plt.subplot(2,2,1)
plt.plot(x,f1,label="f(x) = 3x-4", color ='blue')
plt.title("f(x) = 3x-4")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.legend()
plt.grid()

plt.subplot(2,2,2)
plt.plot(x,f2,label="f(x)x^2 + 2x -15")
plt.title("f(x) = x^2+2x-15")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.legend()
plt.grid()

plt.subplot(2,2,3)
plt.plot(x,f3,label="f(x) = 5(x-1)(x-2)(x-3)", color ='green')
plt.title("f(x) = 5(x-1)(x-2)(x-3)")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.legend()
plt.grid()

plt.subplot(2,2,4)
plt.plot(x,f4,label="f(x) = e^x", color ='red')
plt.title("f(x) = e^x")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.legend()
plt.grid()

plt.tight_layout()
plt.show()
In [12]: x = np.arange(1,101)
f_log = np.log(x)

plt.figure(figsize=(10,6))
plt.plot(x,f_log,label="f(x) = log(x)", color ='purple')
plt.title("f(x) = log(x)")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.legend()
plt.grid()
In [14]: #question2

In [33]: x = np.linspace(-2*np.pi,2*np.pi,500)

f_sin = np.sin(x)
f_cos = np.cos(x)
f_tan=np.tan(x)
f_cot = 1/np.tan(x)

f_cot[np.isinf(f_cot)] =np.nan
plt.figure(figsize=(12,10))
plt.subplot(2,2,1)
plt.plot(x,f_sin,label="g(x) =sin(x) ", color ='blue')
plt.title("f(x) = sin(x)")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.legend()
plt.grid()

plt.subplot(2,2,2)
plt.plot(x,f_cos,label="f(x) = cos(x)", color ='orange')
plt.title("f(x) = cos(x)")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.legend()
plt.grid()

plt.subplot(2,2,3)
plt.plot(x,f_tan,label="h(x) = tan(x)", color ='green')
plt.title("h(x) = tan(x)")
plt.xlabel("x")
plt.ylabel("h(x)")
plt.legend()
plt.grid()
plt.subplot(2,2,4)
plt.plot(x,f_cot,label="k(x) = cot(x)", color ='red')
plt.title("k(x) = cot(x)")
plt.xlabel("x")
plt.ylabel("k(x)")
plt.legend()
plt.grid()

plt.tight_layout()
plt.sow()

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[33], line 44
41 plt.grid()
43 plt.tight_layout()
---> 44 plt.sow()

AttributeError: module 'matplotlib.pyplot' has no attribute 'sow'

In [ ]:

In [ ]:

In [ ]:
In [ ]:

In [ ]:

You might also like