Skip to content

Latest commit

 

History

History
67 lines (48 loc) · 1.29 KB

matplotlib_exercises.md

File metadata and controls

67 lines (48 loc) · 1.29 KB

Matplotlib Exercises

These exercises are designed to help you understand the key functionality of Matplotlib.

1. Line Plot

x = [1, 2, 3, 4, 5]
y = [2, 4, 3, 6, 5]
  • Create a simple line plot of x vs y
  • Add a title and axis labels
  • Plot the data using:
    • a dashed line
    • circular markers
    • a green colour

2. Scatter Plot

height = [150, 155, 160, 165, 170, 175]
weight = [50, 55, 60, 65, 70, 75]
  • Create a scatter plot showing the relationship between height and weight.
  • Label the axes clearly.

3. Bar Chart

fruits = ["Apples", "Bananas", "Cherries", "Dates"]
sales = [50, 75, 40, 20]
  • Create a bar chart showing fruit sales.
  • Add a title and rotate the x‑axis labels if needed.

4. Horizontal Bar Chart

countries = ["UK", "USA", "Germany", "France"]
population = [67, 331, 83, 65]
  • Create a horizontal bar chart.
  • Add axis labels and a title.

5. Histogram

scores = [55, 60, 62, 65, 70, 72, 75, 80, 85, 90]
  • Plot a histogram of the scores using 5 bins.
  • Add a title and label the x‑axis.

6. Multiple Lines on One Plot

months = ["Jan", "Feb", "Mar", "Apr"]
product_A = [30, 35, 40, 38]
product_B = [20, 22, 25, 30]
  • Plot both product lines on the same figure.
  • Add a legend to distinguish them.