10/11/2025, 14:39 Matplotlib plotting examples
🧮 Program 1: Line Plot
import [Link] as plt # Data for plotting x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8,
10] # Create a line plot [Link](x, y, color='blue', marker='o', linestyle='--') # Add
labels and title [Link]("Simple Line Plot") [Link]("X-axis") [Link]("Y-axis") #
Display the graph [Link]()
📊 Output:
A blue dashed line with circular markers showing a linear relationship between X and Y.
🖼️ Example Plot:
Y
|
| o
| o
| o
| o
| o
+------------------ X
📊 Program 2: Bar Graph
import [Link] as plt # Data subjects = ['Math', 'Science', 'English',
'History', 'Computer'] marks = [85, 90, 75, 80, 95] # Create bar graph [Link](subjects,
marks, color='orange') # Add labels and title [Link]("Marks of a Student")
[Link]("Subjects") [Link]("Marks") # Display the graph [Link]()
📊 Output:
An orange bar chart showing marks in different subjects.
🖼️ Example Plot:
Marks
|
100|
90| █
80| █ █
70| █ █
60|
[Link] 1/4
10/11/2025, 14:39 Matplotlib plotting examples
50|
+-------------------------
Math Sci Eng His Comp
🔴 Program 3: Scatter Plot
import [Link] as plt # Data height = [150, 160, 170, 180, 190] weight = [50,
60, 70, 80, 90] # Scatter plot [Link](height, weight, color='red') # Add labels and
title [Link]("Height vs Weight") [Link]("Height (cm)") [Link]("Weight (kg)")
[Link]()
📊 Output:
A red scatter plot showing individual data points of height vs. weight.
🖼️ Example Plot:
Weight (kg)
|
| *
| *
| *
| *
|*
+---------------- Height (cm)
🥧 Program 4: Pie Chart
import [Link] as plt # Data activities = ['Study', 'Sleep', 'Exercise',
'Leisure'] time_spent = [8, 7, 2, 7] # Create pie chart [Link](time_spent,
labels=activities, autopct='%1.1f%%', startangle=90) # Add title [Link]("Daily Time
Distribution") [Link]()
📊 Output:
A pie chart showing how a person spends their day.
🖼️ Example Plot:
[Link] 2/4
10/11/2025, 14:39 Matplotlib plotting examples
________
/ \
| Study 33%|
\ Sleep 29% /
\_________/
Exercise 8% Leisure 30%
📈 Program 5: Multiple Line Graphs
import [Link] as plt # Data x = [1, 2, 3, 4, 5] y1 = [2, 4, 6, 8, 10] y2 = [1,
3, 5, 7, 9] # Plotting multiple lines [Link](x, y1, label='Even Series', color='green',
marker='o') [Link](x, y2, label='Odd Series', color='purple', marker='x') # Add labels,
title, and legend [Link]("Multiple Line Graphs") [Link]("X-axis") [Link]("Y-
axis") [Link]() [Link]()
📊 Output:
A graph with two lines — one for even numbers and one for odd numbers.
🖼️ Example Plot:
Y
| o x
| o x x
| o x x
| o x x
| o x
+------------------ X
✅ Summary of Concepts Used:
Program Type of Plot Function Used Key Feature
1 Line Plot [Link]() Shows relation between X & Y
2 Bar Graph [Link]() Compares quantities
3 Scatter Plot [Link]() Displays data distribution
[Link] 3/4
10/11/2025, 14:39 Matplotlib plotting examples
Program Type of Plot Function Used Key Feature
4 Pie Chart [Link]() Shows proportions
5 Multi-Line [Link]() Compares multiple datasets
[Link] 4/4