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

Lab Record Set 3

The document contains Python code examples for plotting various types of graphs using matplotlib. It includes programs to plot bar graphs for student marks, a line graph for crop production from a CSV file, and a histogram for student heights across different age groups. Each example demonstrates how to input data and visualize it effectively.

Uploaded by

sivasudh916
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)
7 views5 pages

Lab Record Set 3

The document contains Python code examples for plotting various types of graphs using matplotlib. It includes programs to plot bar graphs for student marks, a line graph for crop production from a CSV file, and a histogram for student heights across different age groups. Each example demonstrates how to input data and visualize it effectively.

Uploaded by

sivasudh916
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

EX:NO:7

DATE:

WRITE A PYTHON PROGRAM TO ACCPET 5 SUBJECTS MARKS FROM USER AND PLOT THEM IN BAR GRAPH

CODE:

import matplotlib.pyplot as plt


# Input marks for 5 subjects
subjects = ['Accountancy', 'English', 'Economics', 'Banking','IP']
marks = []
# Get the marks from the user
for i in subjects:
mark = int(input("Enter the marks for "+i))
marks.append(mark)
# Plotting the bar graph
plt.bar(subjects, marks, color='orange')
# Adding titles and labels
plt.title('Marks of 5 Subjects')
plt.xlabel('Subjects')
plt.ylabel('Marks')
# Show the plot
plt.show()
EX:NO:8

DATE:

WRITEA PYTHON PROGRAM TO CREATE A DATAFRAMETHAT CONTAINS LIST OF TOP 3 STUDENTS IN


SCIENCE,COMM AND HUMM BATCHES AND PLOT THEM IN BAR GRAPH

CODEl

import pandas as pd
import matplotlib.pyplot as plt
# Data for top 3 students in each batch
data = {
'Science': [95, 90, 88,],
'Commerce':[92, 89, 85],
'Humanities':[94, 91, 87]
}
df= pd.DataFrame(data,index=['1st', '2nd', '3rd'])
df.plot(kind='bar')
plt.title('Top 3 Students in Science, Commerce, and Humanities')
plt.xlabel('Position')
plt.ylabel('Marks')
plt.legend(title='Batch')
# Show the plot
plt.show()
EX:NO:9

DATE:

WRITE A PYTHON PROGRAM TO PLOT A LINE GRAPH TO READ A CSV FILE ‘PRODCUTION.csv’ WHICH CONTAINS
THE PRODCUTION DETAILS OF RICE ,WHEAT AND BARLY

CODE:

import pandas as pd
import matplotlib.pyplot as plt
# Read data from the CSV file
data = pd.read_csv('production.csv')
# Plotting the line graph
plt.plot(data['Year'], data['Rice'], marker='o', label='Rice', color='green')
plt.plot(data['Year'], data['Wheat'], marker='o', label='Wheat', color='gold')
plt.plot(data['Year'], data['Barley'], marker='o', label='Barley', color='brown')
# Adding labels and title
plt.title('Crop Production Over Years')
plt.xlabel('Year')
plt.ylabel('Production (in tons)')
plt.xticks(data['Year']) # Set x-ticks to show each year
plt.legend()
plt.grid()
# Display the line graph
plt.show()
EX:NO 10
DATE:

WRITE A PYTHON PROGRAM TO PLOT THE FOLLOWING DATA ON HEIGHT OF STUDENTS IN DIFFERENT AGE GROUPS IN
A HISTOGRAM
heights = {
'0-2': [50, 55, 60, 65, 58],
'3-5': [80, 85, 90, 95],
'6-8': [110, 115, 120, 125],
'9-11': [140, 145, 150, 155],
'12-14': [160, 165, 170, 175]
}

CODE:
import matplotlib.pyplot as plt
# Sample height data for different age groups
heights = {
'0-2': [50, 55, 60, 65, 58],
'3-5': [80, 85, 90, 95],
'6-8': [110, 115, 120, 125],
'9-11': [140, 145, 150, 155],
'12-14': [160, 165, 170, 175]
}
# Flatten the data and create age group labels
age_groups = []
height_values = []
for age, heights in heights.items():
age_groups.extend([age] * len(heights)) # Repeat age group for each height
height_values.extend(heights) # Add height values
# Create a histogram
plt.hist(age_groups, weights=height_values, bins=len(heights), color='skyblue', edgecolor='black')
# Adding titles and labels
plt.title('Height Distribution by Age Group')
plt.xlabel('Age Group')
plt.ylabel('Height (cm)')
# Show the plot
plt.grid(axis='y')
plt.tight_layout()
plt.show()

You might also like