Introduction_of_matplotlib1
Introduction_of_matplotlib1
pyplot as plt
import numpy as np
In [13]: #Bar plot vertical--it is work on numerical(number of fruit) and categorical(fruit name)
fruit = np.array(["Apple", "Banana", "Orange", "Watermelon"])
fruit_number = np.array([100, 80, 120, 50])
color = ["red", "yellow", "orange", "green"]
In [5]: #pie plot--it is work on numerical(percentage of fruits) and categorical(fruit name) data
x = np.array([25, 35, 20, 20])
my_labels = ["Apple", "Banana", "Orange", "Watermelon"]
my_explode = [0, 0.2, 0, 0]
subplot used to users can easily create multiple plots in a single figure, making comparing and analyzing different datasets or variables
In [4]: import matplotlib.pyplot as plt
import numpy as np
#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([0, 8, 6, 10])
plt.subplot(1, 2, 1)
#the figure has 1 row, 2 columns, and this plot is the first plot.
plt.plot(x,y)
plt.title("SALES")
plt.xlabel("Month")
plt.ylabel("Number of packet")
#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([0, 30, 20, 40])
plt.subplot(1, 2, 2)
#the figure has 1 row, 2 columns, and this plot is the second plot.
plt.plot(x,y)
plt.title("INCOME")
plt.xlabel("Month")
plt.ylabel("Amount in thousands")
plt.suptitle("MY SHOP")
plt.show()
A scatter plot in Matplotlib is used to visually represent the relationship between two numerical variables by plotting individual data points on a graph
In [7]: #scatter plot
import matplotlib.pyplot as plt
import numpy as np
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,77,85,86])
plt.xlabel("Age of car")
plt.ylabel("Speed of car")
plt.title("Scatter plot of car")
plt.scatter(x, y)
plt.show()
Histogram A histogram is a graph showing frequency distributions. It is a graph showing the number of observations within each given interval.
In [8]: import numpy as np
print(x)
[73 92 61 71 58 42 60 86 90 61 82 50 68 72 53 90 67 82 71 65 90 48 57 85
58 71 66 48 93 50 44 51 86 75 84 86 43 95 46 40 46 46 51 76 60 42 91 41
41 79 56 53 55 41 79 87 75 40 94 92 72 67 49 43 99 68 90 80 89 86 73 58
66 69 91 42 80 53 60 72 49 87 44 72 92 41 41 76 71 56 89 96 72 51 91 65
40 76 50 83 45 45 77 88 74 53 93 50 97 88 55 55 66 96 43 85 79 70 71 93
77 92 95 66 99 59 79 93 45 69 66 68 41 42 70 42 41 89 43 50 54 45 68 64
92 74 56 52 73 63 56 61 50 61 92 85 52 88 84 88 87 57 68 66 76 47 96 87
40 83 70 45 56 72 42 51 42 43 51 89 42 57 84 59 85 83 70 68 62 89 52 49
98 85 79 57 73 63 53 72]
In [ ]: