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

Ai Lab13

This document contains the objective, theory, and programming tasks for a lab on SciPy and Matplotlib in Python. The objective is to perform scientific computing and technical computing with plotting using these libraries. The theory section explains that SciPy is a library for mathematical and scientific computing that builds on NumPy arrays, and Matplotlib is used for 2D plotting of arrays. The programming tasks demonstrate plotting various functions like parabolas, sine/cosine waves, and square/cube functions using SciPy and Matplotlib.

Uploaded by

Hamna Amir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views5 pages

Ai Lab13

This document contains the objective, theory, and programming tasks for a lab on SciPy and Matplotlib in Python. The objective is to perform scientific computing and technical computing with plotting using these libraries. The theory section explains that SciPy is a library for mathematical and scientific computing that builds on NumPy arrays, and Matplotlib is used for 2D plotting of arrays. The programming tasks demonstrate plotting various functions like parabolas, sine/cosine waves, and square/cube functions using SciPy and Matplotlib.

Uploaded by

Hamna Amir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

NAME: HAMNA AMIR ROLL NO: 2020F-BCE-090 SEC:B

LAB#13
(SCIPY AND MATPLOTLIB)

OBJECTIVE:-
Scientific computing and technical computing with plotting using SciPy and matplotlib
library in python
THEORY:
SciPy:
SciPy is a library of algorithms and mathematical tools built to work with NumPy arrays.SciPy,
pronounced as Sigh Pi, is a scientific python open source library to perform Mathematical, Scientific and
Engineering Computations.
The SciPy library depends on NumPy, which provides convenient and fast N-dimensional array
manipulation. The SciPy library is built to work with NumPy arrays and provides many userfriendly and
efficient numerical practices such as routines for numerical integration and optimization. Together, they
run on all popular operating systems, are quick to install and are free of charge. NumPy and SciPy are
easy to use, but powerful enough to depend on by some of the world's leading scientists and engineers.
Importing the SciPy module:
There are several ways to import SciPy. The standard approach is to use a simple import statement:
import scipy
However, for large amounts of calls to SciPy functions, it can become tedious to write numpy.X over and
over again. Instead, it is common to import under the briefer name sp:
import scipy as sp
This statement will allow us to access SciPy objects using sp. X instead of scipy X. It is also possible to
import SciPy directly into the current namespace so that we don't have to use dot notation at all, but rather
simply call the functions as if they were built-in:
from scipy import *
if you want help regarding SciPy, or anything need to know about SciPy in python‘s editor , you may
type: help(scipy) help(scipy.zeros

CE 415: Artificial Intelligence


NAME: HAMNA AMIR ROLL NO: 2020F-BCE-090 SEC:B

LAB TASK:-

PROGRAM#1
Using multiple Plotting example, change the colour of line using plt.gca( ) and adding legend to
the plot using Matplotlib legend( ). Output looks alike :

SOURCE CODE:-

import matplotlib.pyplot as plt


import numpy as np
x = np.arrange(10)
plt.gca().set_color_cycle(['red', 'green', 'blue', 'yellow'])
plt.plot(x,x)
plt.plot(x, 2*x)
plt.plot(x, 3*x)
plt.plot(x, 4*x)
plt.legend([‘y = x’, ‘y = 2x’, ‘y = 3x’, ‘y = 4x’], loc = ‘upper left’)
plt.show()

OUTPUT:-

CE 415: Artificial Intelligence


NAME: HAMNA AMIR ROLL NO: 2020F-BCE-090 SEC:B

PROGRAM#02
Plot function with Matplotlib. First, import SciPy and Matplotlib, some points on the (0, 1) interval and
then plot a parabola defined by the above interval.

SOURCE CODE:-
import scipy as sp
import matplotlib.pylab as plt
t = sp.linspace (0, 1, 100)
plt.plot(t, t^ ** 2)
plt.show()
OUTPUT:-

CE 415: Artificial Intelligence


NAME: HAMNA AMIR ROLL NO: 2020F-BCE-090 SEC:B

PROGRAM#03

Plot sine and cosine function using Numpy and Matplotlib library.

SOURCE CODE:-

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace (0, 5, 100)
c = np.cos (x)
S-np.sin (x)
plt.plot (x, c)
plt.plot (x, s)
plt.legend (['Cosine Function', 'Sine Function'], loc = ‘upper right’)
plt.show()
OUTPUT:-

PROGRAM#04
Plot square and cube function using Scipy and Matplotlib library with linspace interval (0,5). Output
looks alike:

CE 415: Artificial Intelligence


NAME: HAMNA AMIR ROLL NO: 2020F-BCE-090 SEC:B

SOURCE CODE:-

import scipy as sp
import matplotlib.pyplot as plt
x = sp.linspace (0, 5, 10)
y1 = x**2
y2 = x**3
plt.plot(x, y1, ‘b’)
plt.plot(x, y2, ‘g’)
plt.legend ([‘y = x^2’, ‘y = x^3], loc = ‘upper left’)
plt,xlabel(‘X’)
plt,ylabel(‘Y’)
plt.show()

OUTPUT:-

CE 415: Artificial Intelligence

You might also like