PRACTICAL QUESTIONS ON MATPLOTLIB
1. Plot a simple line graph
Write a Python program using matplotlib to plot:
• x = [1, 2, 3, 4]
• y = [2, 4, 1, 5]
Add labels and a title.
2. Plot two lines on the same graph
Write a Python program using matplotlib to plot two-line plots:
• Line 1: x=[1,2,3], y=[1,4,9]
• Line 2: x=[1,2,3], y=[2,3,6]
Add legend.
3. Bar chart of student marks
Write a Python program using matplotlib to create a vertical bar chart.
Add:
• Title
• X and Y labels
• Different bar colors
Given:
subjects = ['Math', 'Science', 'English']
marks = [88, 92, 79]
4. Horizontal bar chart
Create a horizontal bar chart for:
languages = ['Python','Java','C++']
popularity = [60, 45, 30]
5. Pie chart
Create a pie chart of:
• ['Apple', 'Samsung', 'Xiaomi']
• [50, 30, 20]
Add:
• Percentage labels
• Title
• Explode one slice
6. Scatter plot
Plot a scatter plot of:
height = [150, 160, 170, 180]
weight = [50, 60, 72, 85]
Add color & size variation.
7. Histogram
Plot a histogram of marks:
marks = [56, 78, 45, 89, 90, 65, 74, 88, 92, 58]