Page 237 - AI Ver 1.0 Class 10
P. 237

Brainy Fact

                        You may create a figure with many plots known as subplots side by side sharing either the same x-axis or
                        same y-axis. Following is the code to create 3 subplots with shared y-axis:

                        fig, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True)



                 Box Plot (Whisker Plot)

                 Box Plot represents the summary of the set of data values where a box is created for each having properties like
                 minimum, first quartile, median, third quartile and maximum. A vertical line goes through the box at the median.
                 Here x-axis denotes the data to be plotted while the y-axis shows the frequency distribution.
                 Box plots can also be used to plot outliers and these outliers are plotted outside the graph as dots or circles
                 since they do not belong to the range of data and are part of the graph for visualisation.

                 The six parts of the box plots are:
                    • First Quartile (Q1):  From 0 percentile to 25th percentile: the middle number between the smallest number
                   and the median of the dataset.

                    • Second Quartile/Median (Q2): From 25th Percentile to 50th percentile: the middle value of the dataset
                   where 50th percentile is also termed as  mean of the whole distribution.

                    • Third Quartile (Q3): From 50th percentile to 75th percentile: the middle value between the median and the
                   highest value of the dataset.
                    • Interquartile range (IQR): From 25th to 75th percentile.

                    • Fourth Quartile (whiskers plot): From 75th percentile to 100th percentile.

                    • Outliers: Shown as small circles scattered outside the box plots.
                                    First quartile (25th percentile)         Second quartile (75th percentile)
                                             Q 1          Median                    Q 3
                           Min (Q1-1.5*IQR)                                                   Max (Q3+1.5*IQR)



                          Outliers    Whisker                                             Whisker



                                                          Interquartile range (IQR)

                 Matplotlib uses a built-in function boxplot() to create box plots. For example:

                     import matplotlib.pyplot as plt

                     eng = [82,76,24,40,67,62,78,67,72,82]

                     maths = [62,5,32,96,95,90,95,15,71,11]
                     science = [68,86,19,49,15,16,16,75,65,31]





                                                                                              Data Science  235
   232   233   234   235   236   237   238   239   240   241   242