0% found this document useful (0 votes)
10 views7 pages

Practical Programs (8-15)

The document contains a series of programming exercises demonstrating various tasks in Python, including creating dictionaries, plotting data on pie and bar charts, developing a 3x3 matrix, and working with NumPy arrays. Each program includes an aim, code, and a result indicating successful execution. The exercises also cover loading and manipulating images using OpenCV and Matplotlib.

Uploaded by

rahulstudies.77
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)
10 views7 pages

Practical Programs (8-15)

The document contains a series of programming exercises demonstrating various tasks in Python, including creating dictionaries, plotting data on pie and bar charts, developing a 3x3 matrix, and working with NumPy arrays. Each program includes an aim, code, and a result indicating successful execution. The exercises also cover loading and manipulating images using OpenCV and Matplotlib.

Uploaded by

rahulstudies.77
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/ 7

Program 8:Write a program to create a dictionary.

Aim: Write a program to create a dictionary.

Code:

# creating dictionary
person = {"name": "Priya", "age": 18, "address": "Delhi", "phone number": "5575-1234"}
# printing dictionary
print(person)

Result: Thus, the program has been executed successfully.

Program 9: plot the data on the pie chart.


Aim:Write a program to plot the data on the pie chart.
Code:
import matplotlib.pyplot as plt
import numpy as np
y = np.array([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
plt.pie(y, labels = mylabels)
plt.show()

Result: Thus, the program has been executed successfully.


Program 10: Represent data on the ratings of mobile games on barchart.
Aim:Write a program to represent the data on the ratings of mobile games on
barchart.
Code:

import matplotlib.pyplot as plt


#Creating lists for data
games=['Pubg', 'FreeFire', 'MineCraft', 'GTA-V','Call of duty', 'FIFA 22']
rating=[4.5,4.8,4.7,4.6,4.1,4.3]
#Creating bar graph with different bar colours
plt.bar(games,rating,color=['black', 'red', 'green', 'blue', 'yellow'])
#Customizing the bar graph
plt.title("Games Rating 2022")
plt.xlabel('Games')
plt.ylabel('Rating')
plt.legend();
plt.show()

Result: Thus, the program has been executed successfully.


Program 11. Matrix of 3x3 with values from 11 to28.
Aim: Write a program to develop a matrix of 3x3 with values from 11 to28.
Code:
#import numpy package
import numpy as np
#Creating array using arange() function
arr=np.arange(11,28,2)
#reshaping array for 2D
arr=arr.reshape(3,3)
#printing array
print(arr)

Result: Thus, the program has been executed successfully.


Program 12: Plot the data on the line chart
Aim: Consider the following data of a clothes store and plot the data on the line
chart:
Month Jeans T-Shirts Shirts
March : 1500 4400 6500
April :3500 4500 5000
May: 6500 5500 5800
June :6700 6000 6300
July :6000 5600 6200
August :6800 6300 4500
Code:
import matplotlib.pyplot as pp
mon =['March','April','May','June','July','August']
jeans= [1500,3500,6500,6700,6000,6800]
ts = [4400,4500,5500,6000,5600,6300]
sh = [6500,5000,5800,6300,6200,4500]
pp.plot(mon,jeans,label='Mask',color='g',linestyle='dashed', linewidth=4,\
marker='o', markerfacecolor='k', markeredgecolor='r')
pp.plot(mon,ts,label='Mask',color='b',linestyle='dashed', linewidth=4,\
marker='3', markerfacecolor='k', markeredgecolor='g')
pp.plot(mon,sh,label='Mask',color='r',linestyle='dashed', linewidth=4,\
marker='v', markerfacecolor='k', markeredgecolor='b')
pp.title("Apna Garment Store")
pp.xlabel("Months")
pp.ylabel("Garments")
pp.legend()
pp.show()
Result: Thus, the program has been executed successfully.
Program 13: Minimum and Maximum Value of NumPy Array

Aim:Write a program to find Minimum and Maximum Value of NumPy Array

Code:

# import numpy library


import numpy
# creating a numpy array of integers
arr = numpy.array([1, 5, 4, 8, 3, 7])
# finding the maximum and
# minimum element in the array
max_element = numpy.max(arr)
min_element = numpy.min(arr)
# printing the result
print('maximum element in the array is: ', max_element)
print('minimum element in the array is: ',min_element)

Result: Thus, the program has been executed successfully.


Program 14: To load an image and give the title of the image

Aim: Write a program Load an image and Give the title of the image.

Code:

#import required module cv2, matplotlib and numpy

import cv2

import matplotlib.pyplot as plt

import numpy as np

#Load the image file into memory

img = cv2.imread('octopus.png')

#Display Image

plt.imshow(img)

plt.title('Octopus')

plt.axis('off')

plt.show()

Result: Thus, the program has been executed successfully.


Program 15: Change the colour of image

Aim: To write a program to Change the colour of image

Code:

#import required module cv2, matplotlib and numpy

import cv2

import matplotlib.pyplot as plt

import numpy as np

#Load the image file into memory

img = cv2.imread('octopus.png')

#Chaning image colour image colour

plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))

plt.title('Octopus')

plt.axis('off')

plt.show()

Result: Thus, the program has been executed successfully

You might also like