0% found this document useful (0 votes)
33 views16 pages

DSP LAB-3 (Part-A)

Uploaded by

cosmicdestroyer7
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)
33 views16 pages

DSP LAB-3 (Part-A)

Uploaded by

cosmicdestroyer7
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

Data Science using Python Lab

1. Line plots.
# importing the required libraries
import [Link] as plt
import numpy as np
# define data values
x = [Link]([1, 2, 3, 4]) # X-axis points
y = x*2 # Y-axis points
[Link](x, y) # Plot the chart
[Link]() # display
----------------------------------------------------------------

import [Link] as plt


import numpy as np
# Define X and Y variable data
x = [Link]([1, 2, 3, 4])
y = x*2
[Link](x, y)
[Link]("X-axis") # add X-axis label
[Link]("Y-axis") # add Y-axis label
[Link]("Any suitable title") # add title
[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
x = [Link]([1, 2, 3, 4])
y = x*2
[Link](x, y)
[Link]("X-axis")
[Link]("Y-axis")
[Link]("Any suitable title")
[Link]() # show first chart
# The figure() function helps in creating a
# new figure that can hold a new chart in it.
[Link]()
x1 = [2, 4, 6, 8]
y1 = [3, 5, 7, 9]
[Link](x1, y1, '-.')
# Show another chart with '-' dotted line
[Link]()
Data Science using Python Lab

----------------------------------------------------------------

import [Link] as plt


import numpy as np
x = [Link]([1, 2, 3, 4])
y = x*2
# first plot with X and Y data
[Link](x, y)
x1 = [2, 4, 6, 8]
y1 = [3, 5, 7, 9]
# second plot with x1 and y1 data
[Link](x1, y1, '-.')
[Link]("X-axis data")
[Link]("Y-axis data")
[Link]('multiple plots')
[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
x = [Link]([1, 2, 3, 4])
y = x*2
[Link](x, y)
x1 = [2, 4, 6, 8]
y1 = [3, 5, 7, 9]
[Link](x, y1, '-.')
----------------------------------------------------------------

import [Link] as plt


import numpy as np
ypoints = [Link]([3, 8, 1, 10])
[Link](ypoints, linestyle = 'dotted') #dashed
[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
ypoints = [Link]([3, 8, 1, 10])
[Link](ypoints, color = 'r')
Data Science using Python Lab

[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
ypoints = [Link]([3, 8, 1, 10])
[Link](ypoints, linewidth = '20.5')
[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
x1 = [Link]([0, 1, 2, 3])
y1 = [Link]([3, 8, 1, 10])
x2 = [Link]([0, 1, 2, 3])
y2 = [Link]([6, 2, 7, 11])
[Link](x1, y1, x2, y2)
[Link]()

[Link] Plots.
import [Link] as plt
x =[5, 7, 8, 7, 2, 17, 2, 9,
4, 11, 12, 9, 6]
y =[99, 86, 87, 88, 100, 86, 103, 87, 94, 78, 77, 85, 86]
[Link](x, y, c ="blue")
# To show the plot
[Link]()
----------------------------------------------------------------

import [Link] as plt


# dataset-1
x1 = [89, 43, 36, 36, 95, 10,66, 34, 38, 20]
y1 = [21, 46, 3, 35, 67, 95,53, 72, 58, 10]
# dataset2
x2 = [26, 29, 48, 64, 6, 5,36, 66, 72, 40]
y2 = [26, 34, 90, 33, 38,20, 56, 2, 47, 15]
[Link](x1, y1, c ="pink",linewidths = 2,marker ="s",edgecolor ="green",s = 50)
Data Science using Python Lab

[Link](x2, y2, c ="yellow",linewidths = 2,marker ="^",edgecolor ="red",s = 200)


[Link]("X-axis")
[Link]("Y-axis")
[Link]()
----------------------------------------------------------------

import [Link] as plt


girls_grades = [89, 90, 70, 89, 100, 80, 90, 100, 80, 34]
boys_grades = [30, 29, 49, 48, 100, 48, 38, 45, 20, 30]
grades_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
fig=[Link]()
ax=fig.add_axes([0,0,1,1])
[Link](grades_range, girls_grades, color='r')
[Link](grades_range, boys_grades, color='b')
ax.set_xlabel('Grades Range')
ax.set_ylabel('Grades Scored')
ax.set_title('scatter plot')
[Link]()

[Link] Plots.
# library
import numpy as np
import [Link] as plt
# Create data
x=[1,3,2,5,6]
y=[1,4,6,8,4]
print(x)
----------------------------------------------------------------

# Example Python program to draw an overlapped area plot


# for a pandas DataFrame
import pandas as pd
import [Link] as plot
# Peak Temperature data for two cities
tempData = {"City1":[99, 106, 102, 78],
"City2":[77, 84, 80, 85]};
Data Science using Python Lab

# Seasons
seasons = ("Spring", "Summer", "Fall", "Winter");
# Create a DataFrame instance
dataFrame = [Link](tempData, index=seasons);
#Draw an area plot for the DataFrame data
[Link](kind='area', stacked=False)
[Link](block=True);
----------------------------------------------------------------

# Example Python program that draws a overlapping area


# plot for a pandas DataFrame instance
import pandas as pd
import [Link] as plot
# Number of observations
data = [(25, 1),
(43, 1),
(35, 2),
(34, 4)];
# Years
index = ["2016", "2017", "2018", "2019"]; # (X Axis)
# Name of the Quantities corresponding to the
#observations(Y Axis)
columns = ["Meteors", "Meteorites"];
# Create DataFrame instance
df = [Link](data=data, index = index, columns =
columns);
# Draw an area plot that overlaps
ax = [Link](stacked=True);
[Link](block=True);

[Link] Plots.

import [Link] as plt

import numpy as np

# create data

x = [Link](40)
Data Science using Python Lab

y = [Link](40)

z = [Link](40)

colors = [Link](40)

# use the scatter function

[Link](x, y, s=z*1000,c=colors)

[Link]()

----------------------------------------------------------------

import [Link] as plt

x =[5, 7, 8, 7, 2, 17, 2, 9,4, 11, 12, 9, 6]

y =[99, 86, 87, 88, 100, 86,103, 87, 94, 78, 77, 85, 86][Link](x, y, c ="blue")

# To show the plot

[Link]()

N = 13

colors = [Link](N)

area = (25 * [Link](N))**2

df = [Link]({ 'X': x, 'Y': y, 'Colors': colors, "bubble_size":area})

[Link]('X', 'Y',s='bubble_size',alpha=0.5, data=df,c=colors)

[Link]("X", size=16)

[Link]("y", size=16)

[Link]("Bubble Plot with Matplotlib", size=18)

[Link] Plots.
import [Link] as plt
import numpy as np
x = [Link](["A", "B", "C", "D"])
y = [Link]([3, 8, 1, 10])
[Link](x,y)
Data Science using Python Lab

[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
x = [Link](["A", "B", "C", "D"])
y = [Link]([3, 8, 1, 10])
[Link](x, y)
[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
x = [Link](["A", "B", "C", "D"])
y = [Link]([3, 8, 1, 10])
[Link](x, y, color = "red")
[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
x = [Link](["A", "B", "C", "D"])
y = [Link]([3, 8, 1, 10])
[Link](x, y, width = 0.1)
[Link]()

import [Link] as plt


import numpy as np
x = [Link](["A", "B", "C", "D"])
y = [Link]([3, 8, 1, 10])
[Link](x, y, height = 0.1)
[Link]()
----------------------------------------------------------------

import numpy as np
import [Link] as plt
# creating the dataset
data = {'C':20, 'C++':15, 'Java':30, 'Python':35}
courses = list([Link]())
Data Science using Python Lab

values = list([Link]())
fig = [Link](figsize = (10, 5))
# creating the bar plot
[Link](courses, values, color ='maroon', width = 0.4)
[Link]("Courses offered")
[Link]("No. of students enrolled")
[Link]("Students enrolled in different courses")
[Link]()

----------------------------------------------------------------

import numpy as np
import [Link] as plt
# set width of bar
barWidth = 0.25
fig = [Link](figsize =(12, 8))
# set height of bar
IT = [12, 30, 1, 8, 22]
ECE = [28, 6, 16, 5, 10]
CSE = [29, 3, 24, 25, 17]
# Set position of bar on X axis
br1 = [Link](len(IT))
br2 = [x + barWidth for x in br1]
br3 = [x + barWidth for x in br2]
# Make the plot
[Link](br1, IT, color ='r', width = barWidth,edgecolor ='grey', label ='IT')
----------------------------------------------------------------

import numpy as np
import [Link] as plt
# set width of bar
barWidth = 0.25
fig = [Link](figsize =(12, 8))
# set height of bar
IT = [12, 30, 1, 8, 22]
ECE = [28, 6, 16, 5, 10]
CSE = [29, 3, 24, 25, 17]
Data Science using Python Lab

# Set position of bar on X axis


br1 = [Link](len(IT))
br2 = [x + barWidth for x in br1]
br3 = [x + barWidth for x in br2]
# Make the plot
[Link](br1, IT, color ='r', width = barWidth, edgecolor ='grey', label ='IT')
[Link](br2, ECE, color ='g', width = barWidth, edgecolor ='grey', label ='ECE')
[Link](br3, CSE, color ='b', width = barWidth,edgecolor ='grey', label ='CSE')
# Adding Xticks
[Link]('Branch', fontweight ='bold', fontsize = 15)
[Link]('Students passed', fontweight ='bold', fontsize = 15)
[Link]([r + barWidth for r in range(len(IT))],['2015', '2016', '2017', '2018', '2019'])
[Link]()
[Link]()

[Link] Charts.
import [Link] as plt
import numpy as np
y = [Link]([35,25,25,15])
[Link](y)
[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
y = [Link]([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
[Link](y, labels = mylabels)
[Link]()
----------------------------------------------------------------

import [Link] as plt


import numpy as np
y = [Link]([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
[Link](y, labels = mylabels, startangle = 90)
[Link]()
----------------------------------------------------------------
Data Science using Python Lab

import [Link] as plt


import numpy as np
y = [Link]([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
myexplode = [0.2, 0, 0, 0]
[Link](y, labels = mylabels, explode = myexplode)
[Link]()

----------------------------------------------------------------

import [Link] as plt


import numpy as np
y = [Link]([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
mycolors = ["black", "hotpink", "b", "#4CAF50"]
[Link](y, labels = mylabels, colors = mycolors)
[Link]()
import [Link] as plt
import numpy as np
y = [Link]([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
[Link](y, labels = mylabels)
[Link]()
[Link]()
----------------------------------------------------------------

# Import libraries
from matplotlib import pyplot as plt
import numpy as np
# Creating dataset
cars = ['AUDI', 'BMW', 'FORD','TESLA', 'JAGUAR', 'MERCEDES']
data = [23, 17, 35, 29, 12, 41]
# Creating plot
fig = [Link](figsize =(10, 7))
[Link](data, labels = cars)
# show plot
[Link]()
----------------------------------------------------------------
Data Science using Python Lab

# Import libraries
import numpy as np
import [Link] as plt
# Creating dataset
cars = ['AUDI', 'BMW', 'FORD', 'TESLA', 'JAGUAR', 'MERCEDES']
data = [23, 17, 35, 29, 12, 41]
# Creating explode data
explode = (0.1, 0.0, 0.2, 0.3, 0.0, 0.0)
# Creating color parameters
colors = ( "orange", "cyan", "brown","grey", "indigo", "beige")
# Wedge properties
wp = { 'linewidth' : 1, 'edgecolor' : "green" }
# Creating autocpt arguments
def func(pct, allvalues):
absolute = int(pct / 100.*[Link](allvalues))
return "{:.1f}%\n({:d} g)".format(pct, absolute)
# Creating plot
fig, ax = [Link](figsize =(10, 7))
wedges, texts, autotexts = [Link](data,autopct = lambda pct: func(pct, data),explode = explode, labels = cars, shadow =
True,colors = colors,startangle = 90,wedgeprops = wp, textprops = dict(color ="magenta"))
# Adding legend
[Link](wedges, cars, title ="Cars",loc ="center left", bbox_to_anchor =(1, 0, 0.5, 1))
[Link](autotexts, size = 8, weight ="bold")
ax.set_title("Customizing pie chart")
# show plot
[Link]()

[Link] Plots.
# Import libraries Output:[1, 2, 3, 4]

import [Link] as plt

import numpy as np

# Creating dataset

data = [1,2,3,4,]

print(data)

fig = [Link](figsize =(10, 5))


Data Science using Python Lab

# Creating plot

[Link](data)

# show plot

[Link]()

----------------------------------------------------------------

import pandas as pd

import numpy as np

df = [Link]([Link](10, 6), columns=['A', 'B', 'C', 'D', 'E','F'])

# Import libraries

import [Link] as plt

import numpy as np

# Creating dataset

[Link](10)

data_1 = [Link](100, 10, 200)

data_2 = [Link](90, 20, 200)

data_3 = [Link](80, 30, 200)

data_4 = [Link](70, 40, 200)

data = [data_1, data_2, data_3, data_4]

fig = [Link](figsize =(10, 7))

----------------------------------------------------------------

import [Link] as plt

value1 =[82,76,24,40,67,62,75,78,71,32,98,89,78,67,72,82,87,66,56,52]

value2=[62,5,91,25,36,32,96,95,3,90,95,32,27,55,100,15,71,11,37,21]

value3=[23,89,12,78,72,89,25,69,68,86,19,49,15,16,16,75,65,31,25,52]
Data Science using Python Lab

value4=[59,73,70,16,81,61,88,98,10,87,29,72,16,23,72,88,78,99,75,30]

box_plot_data=[value1,value2,value3,value4]

[Link](box_plot_data)

[Link]()

----------------------------------------------------------------

import [Link] as plt

value1 =[82,76,24,40,67,62,75,78,71,32,98,89,78,67,72,82,87,66,56,52]

value2=[62,5,91,25,36,32,96,95,3,90,95,32,27,55,100,15,71,11,37,21]

import [Link] as plt

value1 =[82,76,24,40,67,62,75,78,71,32,98,89,78,67,72,82,87,66,56,52]

value2=[62,5,91,25,36,32,96,95,3,90,95,32,27,55,100,15,71,11,37,21]

value3=[23,89,12,78,72,89,25,69,68,86,19,49,15,16,16,75,65,31,25,52]

value4=[59,73,70,16,81,61,88,98,10,87,29,72,16,23,72,88,78,99,75,30]

box_plot_data=[value1,value2,value3,value4]

[Link](box_plot_data,notch='True',patch_artist=True,labels=['course1','course2','course3','course4'])

[Link]()

----------------------------------------------------------------

import [Link] as plt

value1 =[82,76,24,40,67,62,75,78,71,32,98,89,78,67,72,82,87,66,56,52]

value2=[62,5,91,25,36,32,96,95,3,90,95,32,27,55,100,15,71,11,37,21]

value3=[23,89,12,78,72,89,25,69,68,86,19,49,15,16,16,75,65,31,25,52]

value4=[59,73,70,16,81,61,88,98,10,87,29,72,16,23,72,88,78,99,75,30]

box_plot_data=[value1,value2,value3,value4]

box=[Link](box_plot_data,vert=0,patch_artist=True,labels=['course1','course2','course3','course4'],)
Data Science using Python Lab

colors = ['cyan', 'lightblue', 'lightgreen', 'tan']

for patch, color in zip(box['boxes'], colors):patch.set_facecolor(color)

[Link]()

[Link].
import pandas as pd
import [Link] as plt
data = {'Name':['Arnav', 'Sheela', 'Azhar','Bincy','Yash','Nazar'],
'Height' : [60,61,63,65,61,60],
'Weight' : [47,89,52,58,50,47]}
df=[Link](data)
[Link](kind='hist',edgecolor='Green',linewidth=2,linestyle=':',fill=False,hatch='o')
[Link]()
----------------------------------------------------------------

from matplotlib import pyplot as plt


import numpy as np
# Creating dataset
a = [Link]([1,12,22,21,20,21])
# Creating histogram
[Link](a,bins=5,ec='red',cumulative='True')
#[Link](a,bins=5,ec='red',cumulative='-1')
# Show plot
[Link]('age')
[Link]('count')
[Link]('Histogram Example')
[Link]()
----------------------------------------------------------------

from matplotlib import pyplot as plt


import numpy as np
# Creating dataset
a = [Link]([1,12,22,21,20,21])
# Creating histogram
# bins{int,[Link])
[Link](a,bins=5,ec='red',weights=[2,2,2,2,3,3])
Data Science using Python Lab

# Show plot
[Link]('age')
[Link]('count')
[Link]('Histogram Example')
[Link]()
----------------------------------------------------------------

from matplotlib import pyplot as plt


import numpy as np
# Creating dataset
a = [Link]([22, 87, 5, 43, 56,73, 55, 54, 11,20, 51, 5, 79, 31,27])
# Creating histogram
# bins{int,[Link])
[Link](a,bins=5,ec='red',density='True') #binn=int , ec=edge colour
# Show plot
[Link]('age')
[Link]('count')
[Link]('Histogram Example')
[Link]()
----------------------------------------------------------------

from matplotlib import pyplot as plt


import numpy as np
# Creating dataset
a = [Link]([22, 87, 5, 43, 56,73, 55, 54, 11,20, 51, 5, 79, 31,27])
# Creating histogram
# bins{int,[Link])
[Link](a,bins=5,ec='red') #binn=int , ec=edge colour
# Show plot
[Link]('age')
[Link]('count')
[Link]('Histogram Example')
[Link]()
----------------------------------------------------------------

from matplotlib import pyplot as plt


import numpy as np
# Creating dataset
Data Science using Python Lab

a = [Link]([22, 87, 5, 43, 56,73, 55, 54, 11,20, 51, 5, 79, 31,27])
# Creating histogram
# bins{int,[Link])
[Link](a,bins=5,ec='red') #binn=int , ec=edge colour
[Link](a,bins=[0,25,50,75,100],ec='red') #binn=sequence , ec=edgecolour
[Link](a,bins=[0,25,50,75,100],ec='red') #binn=string , ec=edgecolour
# Show plot
[Link]('age')
[Link]('count')
[Link]('Histogram Example')
[Link]()

You might also like