Unit 3
Unit 3
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y
= [99,86,87,88,111,86,103,87,94,78,77,85,86
]
plt.scatter(x, y)
plt.show()
Compare
x =
np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y =
np.array([99,86,87,88,111,86,103,87,94,78,7
7,85,86])
plt.scatter(x, y, color = 'hotpink')
x =
np.array([2,2,8,1,15,8,12,9,7,3,11,4,7,14,1
2])
y =
np.array([100,105,84,105,90,99,90,95,94,100
,79,112,91,80,85])
plt.scatter(x, y, color = '#88c999')
plt.show()
Size
x =
np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y =
np.array([99,86,87,88,111,86,103,87,94,78,7
7,85,86])
sizes
= np.array([20,50,100,200,500,1000,60,90,10
,300,600,800,75])
plt.scatter(x, y, s=sizes)
plt.show()
Alpha
You can adjust the transparency of the dots with the alpha argument.
x =
np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y =
np.array([99,86,87,88,111,86,103,87,94,78,7
7,85,86])
sizes
= np.array([20,50,100,200,500,1000,60,90,10
,300,600,800,75])
plt.show()
Histogram
A histogram is a graph showing frequency distributions.
It is a graph showing the number of observations within each given interval.
import matplotlib.pyplot as plt
import numpy as np
plt.hist(x)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# Generate random data
np.random.seed(42)
# For reproducibility
data = np.random.randn(1000)
# 1000 random values from a normal distribution
# Create histogram
plt.hist(data, bins=30, edgecolor='black', alpha=0.7)
# Add labels and title
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Histogram Example')
# Show plot
plt.show()
Bar chart
plt.bar(x,y)
plt.show()
x = ["APPLES", "BANANAS"]
y = [400, 350]
plt.bar(x, y)
Horizontal Bars
plt.barh(x, y)
plt.show()
Bar Color
plt.pie(y)
plt.show()
Labels
import numpy as np
import matplotlib.pyplot as plt
x =
np.array([80, 85, 90, 95, 100, 105, 110, 11
5, 120, 125])
y =
np.array([240, 250, 260, 270, 280, 290, 300
, 310, 320, 330])
plt.plot(x, y)
plt.grid(axis = 'x')
plt.show()
Linestyle
plt.plot(ypoints, ls = ':')
Plotting Without Line
plt.plot(xpoints, ypoints)
plt.show()
• A heat map is a two-dimensional representation of data
in which various values are represented by colors. A
simple heat map provides an immediate visual
summary of information across two axes, allowing users
to quickly grasp the most important or relevant data
points.
import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt