0% found this document useful (0 votes)
12 views12 pages

Matplotlib Graphing Techniques

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)
12 views12 pages

Matplotlib Graphing Techniques

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

PRACTICAL-25

Aim: To plot a simple line graph showing the


relationship between two variables.

Source code
# Data
import [Link] as plt
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 35]
# Plotting the line graph
[Link](x, y, color='green', marker='o')
# Adding titles and labels
[Link]('Simple Line Plot')
[Link]('X-axis')
[Link]('Y-axis')
# Display the plot
[Link]()
Output
PRACTICAL-26
Aim: To create a bar chart representing data.

Source code
import [Link] as plt
# Data
categories = ['Math', 'Science', 'English', 'History', 'Geography']
values = [85, 90, 75, 80, 88]
# Plotting the bar chart
[Link](categories, values, color='skyblue')
# Adding titles and labels
[Link]('Subject Scores')
[Link]('Subjects')
[Link]('Scores')
# Display the plot
[Link]()
Output
PRACTICAL-27
Aim: To create a histogram showing the distribution of
data.

Source code
import [Link] as plt
# Data: Age distribution of students
ages = [12, 13, 14, 15, 16, 14, 15, 16, 17, 15, 16, 17, 18, 15, 16]
# Plotting the histogram
[Link](ages, bins=5, color='purple', edgecolor='black')
# Adding titles and labels
[Link]('Age Distribution of Students')
[Link]('Age')
[Link]('Frequency')
# Display the plot
[Link]()

Output
PRACTICAL-28
Aim: To plot a scatter graph to show the relationship
between two variables.

Source code
import [Link] as plt
# Data: Height vs Weight
height = [150, 160, 170, 180, 190]
weight = [50, 60, 70, 80, 90]
# Plotting the scatter plot
[Link](height, weight, color='red')
# Adding titles and labels
[Link]('Height vs Weight')
[Link]('Height (cm)')
[Link]('Weight (kg)')
# Display the plot
[Link]()

Output
PRACTICAL-29
Aim: To create a pie chart showing the percentage
distribution of categories.

Source code
import [Link] as plt
# Data
labels = ['Python', 'Java', 'C++', 'JavaScript']
sizes = [40, 30, 20, 10]
# Plotting the pie chart
[Link](sizes, labels=labels, autopct='%1.1f%%', startangle=90,
colors=['gold', 'yellowgreen', 'lightcoral', 'lightskyblue'])
# Adding title
[Link]('Programming Language Popularity')
# Display the plot
[Link]()

Output
PRACTICAL-30
Aim: To create a line plot and customize it by adding
grid, title, and labels.

Source code
import [Link] as plt
# Data: Sales over 5 months
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']
sales = [5000, 7000, 8000, 6500, 9000]
# Plotting the line graph
[Link](months, sales, color='blue', marker='o')
# Customizing the plot
[Link]('Monthly Sales', fontsize=16)
[Link]('Months', fontsize=12)
[Link]('Sales (in INR)', fontsize=12)
[Link](True)
# Display the plot
[Link]()

Output

You might also like