@@ -40,60 +40,97 @@ Syntax - matplotlib.pyplot.boxplot(data,notch=none,vert=none,patch_artist,widths
40
40
## Implementation of Box Plot in Python
41
41
42
42
### Import libraries
43
+
43
44
import matplotlib.pyplot as plt
45
+
44
46
import numpy as np
45
47
46
48
### Creating dataset
49
+
47
50
np.random.seed(10)
51
+
48
52
data = np.random.normal(100, 20, 200)
53
+
49
54
fig = plt.figure(figsize =(10, 7))
50
55
51
56
### Creating plot
57
+
52
58
plt.boxplot(data)
53
59
54
60
### show plot
61
+
55
62
plt.show()
56
63
57
64
### Implementation of Multiple Box Plot in Python
65
+
58
66
import matplotlib.pyplot as plt
67
+
59
68
import numpy as np
69
+
60
70
np.random.seed(10)
71
+
61
72
dataSet1 = np.random.normal(100, 10, 220)
62
- dataSet2 = np.random.normal(80, 20, 200)
73
+
74
+ dataSet2 = np.random.normal(80, 20, 200)
75
+
63
76
dataSet3 = np.random.normal(60, 35, 220)
77
+
64
78
dataSet4 = np.random.normal(50, 40, 200)
79
+
65
80
dataSet = [ dataSet1, dataSet2, dataSet3, dataSet4]
81
+
66
82
figure = plt.figure(figsize =(10, 7))
83
+
67
84
ax = figure.add_axes([ 0, 0, 1, 1] )
85
+
68
86
bp = ax.boxplot(dataSet)
87
+
69
88
plt.show()
70
89
71
90
### Implementation of Box Plot with Outliers (visual representation of the sales distribution for each product, and the outliers highlight months with exceptionally high or low sales)
91
+
72
92
import matplotlib.pyplot as plt
93
+
73
94
import numpy as np
74
95
75
96
### Data for monthly sales
97
+
76
98
product_A_sales = [ 100, 110, 95, 105, 115, 90, 120, 130, 80, 125, 150, 200]
99
+
77
100
product_B_sales = [ 90, 105, 100, 98, 102, 105, 110, 95, 112, 88, 115, 250]
101
+
78
102
product_C_sales = [ 80, 85, 90, 78, 82, 85, 88, 92, 75, 85, 200, 95]
79
103
80
104
### Introducing outliers
105
+
81
106
product_A_sales.extend([ 300, 80] )
107
+
82
108
product_B_sales.extend([ 50, 300] )
109
+
83
110
product_C_sales.extend([ 70, 250] )
84
111
85
112
### Creating a box plot with outliers
113
+
86
114
plt.boxplot([ product_A_sales, product_B_sales, product_C_sales] , sym='o')
115
+
87
116
plt.title('Monthly Sales Performance by Product with Outliers')
117
+
88
118
plt.xlabel('Products')
119
+
89
120
plt.ylabel('Sales')
121
+
90
122
plt.show()
91
123
92
124
### Implementation of Grouped Box Plot (to compare the exam scores of students from three different classes (A, B, and C))
125
+
93
126
import matplotlib.pyplot as plt
127
+
94
128
import numpy as np
129
+
95
130
class_A_scores = [ 75, 80, 85, 90, 95]
131
+
96
132
class_B_scores = [ 70, 75, 80, 85, 90]
133
+
97
134
class_C_scores = [ 65, 70, 75, 80, 85]
98
135
99
136
### Creating a grouped box plot
0 commit comments