Lab Record Set 3
Lab Record Set 3
DATE:
WRITE A PYTHON PROGRAM TO ACCPET 5 SUBJECTS MARKS FROM USER AND PLOT THEM IN BAR GRAPH
CODE:
DATE:
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()