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

Week 4 Lab Work Matplotlib

The document contains a series of exercises using Python's matplotlib library to create various types of plots, including line graphs, scatter plots, bar graphs, histograms, pie charts, and boxplots. Each exercise includes a code snippet and a description of the expected result. The exercises involve drawing shapes, generating random data, and visualizing statistical information.

Uploaded by

kosssayy431
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 views4 pages

Week 4 Lab Work Matplotlib

The document contains a series of exercises using Python's matplotlib library to create various types of plots, including line graphs, scatter plots, bar graphs, histograms, pie charts, and boxplots. Each exercise includes a code snippet and a description of the expected result. The exercises involve drawing shapes, generating random data, and visualizing statistical information.

Uploaded by

kosssayy431
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

Exercise 1:

 Draw a line from the point (1, 2) to the point (5, 6).
 Draw the point (2, 2) and the point (5, 5).
 Draw a vertical line that passes by x = 3 and an horizontal line that passes by y = 3.
 Draw a line from the point (1, 4) to (2, 6) then to (4, 2) and finally to point (6, 6).

Code Result
import [Link] as plt
import numpy as np

x_axis = [Link]([1, 5])


y_axis = [Link]([2, 6])
[Link](x_axis, y_axis)

x_axis = [Link]([2, 5])


y_axis = [Link]([2, 5])
[Link](x_axis, y_axis, "o")

[Link](x=3, color='r', ls=':',


label=f"Vertical Line")
[Link](y=3, color='b', ls='-.',
label=f"Horizontal Line")

x_axis = [Link]([1, 2, 4, 6])


y_axis = [Link]([4, 6, 2, 6])
[Link](x_axis, y_axis, "r-.D")

[Link]("Graph Title")
[Link]("x-axis Title")
[Link]("y-Axis Title")

[Link]()
[Link]()

Exercise 2:

Draw a scatter plot of the points: (3, 77), (5, 85), (8, 87), (7, 88), (9, 90), (10, 92), (12, 90),
(9, 86), (4, 80), (11, 98), (12, 93), (9, 85), (6, 86).
Code Result
import [Link] as plt
import numpy as np

x = [Link]([3, 5, 8, 7, 9, 10, 12, 9, 4, 11, 12, 9,


6])
y = [Link]([77, 85, 87, 88, 90, 92, 90, 86, 80,
98, 93, 85, 86])

[Link](x, y)
[Link]("Graph Title")
[Link]("x-axis Title")
[Link]("y-Axis Title")
[Link]()

Exercise 3:

Draw a bar graph for the following table:

A B C D
3 7 5 4

Code Result
import [Link] as plt
import numpy as np

x = [Link](["A", "B", "C", "D"])


y = [Link]([3, 7, 5, 4])

[Link](x,y)

[Link]("Graph Title")
[Link]("x-axis Title")
[Link]("y-Axis Title")

[Link]()

Exercise 4:

Generate weights of 250 persons then draw the histogram of weights:

 Use [Link](10, 120, size=(250,)) to generate 250 random integers ranging


from 10 to 120.
Code Result
import [Link] as plt
import numpy as np
x = [Link](10, 120, size=(250,))

[Link](x)

[Link]("Weight Histogram")
[Link]("Weights")
[Link]("Number of Persons")

[Link]()

Exercise 5:

draw pie charts of the following table:

Apples Cherries Bananas Dates


35 10 40 15

Code Result
import [Link] as plt
import numpy as np

mylabels = ["Apples", "Cherries", "Bananas",


"Dates"]
y = [Link]([35, 10, 40, 15])

myexplode = [0.1, 0, 0.1, 0]


[Link](y, labels = mylabels, explode =
myexplode)

[Link]("Pie Title")
[Link]()
[Link]()

Exercise 6:

Generate scores of 100 student in Math then draw the boxplot of the obtained scores:

 Use [Link](34) to generate the same distribution of random data.


 Use [Link](10, 3, 94) to create random data, it takes 10 as mean, 3 as
standard deviation, and 94 as the desired number of values to generate.
 Use the array outliers = [Link]([19, 20, 0, 1, 2, 19]) to generate 6 outliers.

Code Result
import [Link] as plt
import numpy as np

[Link](34)

d = [Link](10, 3, 94)
outliers = [Link]([19, 20, 0, 1, 2, 18])

data = [Link]((d, outliers))

[Link](data, sym="bo") #Default o


# Try: ro, rd, rD, r<, g>, m^
[Link]()

You might also like