Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Tanishq Worksheet Python

Uploaded by

Gautam Passi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Tanishq Worksheet Python

Uploaded by

Gautam Passi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No.

Student Name: Tanishq UID: 24MCI10222


Branch: MCA Section/Group: MAM-4A
Semester: 1st Date of Performance: 1st October 2024
Subject Name: Python Programming Subject Code: 24CAH-606

Q. (a) Write a python program to generate a simple bar graph using matplotlib. The
graph should be properly labelled.

(b)Write a python program to generate Pie-chart using matplotlib. The graph should be
properly labelled.

Aim/Overview of the practical: The aim of this practical is to under stand the basic data
visualization using bar chart.This writing helps you get comfortable with python code for
graphs.

1. Task to be done:
• Import the matplotlib library.
• Then , define the data.
• After defining the data, we have to create the bar graph and labelling the x and y axis.
• Now the last step we have to do is to add title to the graph and display the graph.

2. Code for experiment/practical:

import matplotlib.pyplot as plt

students = ['Anshul ', 'Bobby', 'Chetan', 'aman', 'mota']


marks = [85, 77, 83, 78, 56]

plt.bar(students, marks, color='red')


plt.xlabel('students')
plt.ylabel('marks')
plt.title('Simple Bar Graph')

plt.show()

3. Result/Output/Writing Summary:

Learning outcomes (What I have learnt):

• Learned how to plot graph in python.


• It helps to get the basic understanding of data visualization.
• Learned to use the matplotlib library more efficiently.
• Learned how to generate plots, label, axes, and give titles.
(b)Write a python program to generate Pie-chart using matplotlib. The graph should be
properly labelled.

Aim/Overview of the practical: The aim of this practical is to under stand the basic data
visualization using pie chart. This writing helps you get comfortable with python code for
graphs.

3. Task to be done:
• Import the matplotlib library.
• Then , define the data.
• After defining the data, Create the pie chart .
• Now the last step we have to do is to add a title using plt.title().
• Display the pie chart.

Code for experiment/practical:

import matplotlib.pyplot as plt

import numpy as np

# Data for the pie chart y =

np.array([20, 30, 40, 35])

mylabels = ["C", "C++", "Java", "Python"]

# Plot the pie chart

plt.pie(y, labels=mylabels, autopct="%1.1f%%", startangle=90)

# Adding legend

plt.legend(title="Programming Languages:", loc='upper left')

# Display the pie chart plt.show()


Result/Output/Writing Summary:

Learning outcomes (What I have learnt):

• Learned how to plot pie graph in python.


• It helps to get the basic understanding of data visualization.
• Learned to use the matplotlib library more efficiently.
• Learned how to generate plots, label, axes, and give titles.
• Pie chart gives us more basic understanding of building graphs concept in python.

You might also like