0% found this document useful (0 votes)
2 views2 pages

Matplotlib Pacticals

The document contains four Python programs that utilize the matplotlib library to create different types of charts: a line chart for tracking weekly temperatures, a bar graph for comparing student enrollment across streams, a pie chart for displaying monthly household expenses, and a histogram for showing the distribution of student marks. Each program includes data definitions, chart configurations, and display commands. These examples demonstrate the versatility of matplotlib in visualizing data.

Uploaded by

ajaypalp173
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)
2 views2 pages

Matplotlib Pacticals

The document contains four Python programs that utilize the matplotlib library to create different types of charts: a line chart for tracking weekly temperatures, a bar graph for comparing student enrollment across streams, a pie chart for displaying monthly household expenses, and a histogram for showing the distribution of student marks. Each program includes data definitions, chart configurations, and display commands. These examples demonstrate the versatility of matplotlib in visualizing data.

Uploaded by

ajaypalp173
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

matplotlib programs

Program 1 ; Line Chart: Tracking Weekly


Temperatures
This program demonstrates how to plot a simple line graph with custom labels, titles,
and markers.
Python
import [Link] as plt

# Data for the week


days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
temp = [32, 34, 31, 29, 35, 36, 33]

[Link](days, temp, color='red', marker='o', linestyle='--')

# Adding labels and title


[Link]('Days of the week')
[Link]('Temperature in Celsius')
[Link]('Weekly Temperature Analysis')

[Link]()

Program 2 ; Bar Graph: Comparing Stream


Enrollment
Bar graphs are essential for comparing categories. This example shows how to create
a vertical bar chart with a specific width and color.
Python
import [Link] as plt

# Data for student enrollment


streams = ['Science', 'Commerce', 'Humanities', 'Vocational']
students = [120, 150, 80, 40]

[Link](streams, students, color='skyblue', width=0.5)

[Link]('Streams')
[Link]('Number of Students')
[Link]('Student Enrollment by Stream')

[Link]()
Program 3 ; Pie Chart: Monthly Household
Expenses
The Pie chart is used to show proportions of a whole. We use the explode feature to
highlight a specific section.
Python
import [Link] as plt

# Data for expenses


activities = ['Rent', 'Grocery', 'Bills', 'Leisure']
slices = [40, 30, 20, 10]
cols = ['gold', 'lightgreen', 'lightcoral', 'lightskyblue']

[Link](slices, labels=activities, colors=cols,


startangle=90, shadow=True, explode=(0, 0.1, 0, 0),
autopct='%1.1f%%')

[Link]('Monthly Expense Distribution')


[Link]()

Program 4 ; Histogram: Distribution of Marks


Histograms are used to show frequency distribution of continuous data (like marks or
ages).
Python
import [Link] as plt

# Data: Marks obtained by 20 students


marks = [45, 55, 62, 70, 75, 78, 82, 85, 88, 90, 92, 95, 48, 52, 66, 71, 77, 81,
84, 89]

# Defining bins (intervals)


bins = [40, 50, 60, 70, 80, 90, 100]

[Link](marks, bins, color='purple', edgecolor='black')

[Link]('Marks Range')
[Link]('Number of Students')
[Link]('Distribution of Student Marks')

[Link]()

You might also like