Page 235 - AI Ver 1.0 Class 10
P. 235

For example, marks of 5 subjects to compare, rise in population in five years, changing fuel price every month.
                 Various versions of bar charts exist like single bar chart, double bar chart, etc. can be used. Matplotlib uses a
                 built-in function bar() to create bar charts. For example,


                     import matplotlib.pyplot as plt
                     marks = [23,45,34,41,13,49]
                     plt.bar([“Eng”,“Maths”,“Science”,“SSt”,“2nd Lang”,“Computers”], marks)
                     plt.title(‘Bar Chart’)

                     plt.xlabel(‘Subjects’)
                     plt.ylabel(‘Marks’)

                     plt.show()
                 Output will be:
                                                                   Bar Chart
                                          50


                                          40


                                          30
                                         Marks  20




                                          10


                                           0
                                                  Eng    Maths   Science   SSt    2nd   Computers
                                                                   Subjects       Lang



                 Pie Chart
                 Pie chart is a circular representation of data where each slice shows the relative size of the data. The data is a
                 complete circle equal to 360° with each segment and sectors forming a certain portion of the total(percentage).

                 Matplotlib uses a built-in function pie()to create pie charts. For example,

                     from matplotlib import pyplot as plt
                     import numpy as np
                     fig = plt.figure()
                     ax = fig.add_axes([0,0,1,1])
                     ax.axis(‘equal’)

                     subjects = [“Eng”,“Maths”,“Science”,“SSt”,“2nd Lang”,“Computers”]
                     marks = [23,45,34,41,13,49]
                     ax.pie(marks, labels = subjects, autopct = ‘%1.2f%%’)
                     plt.show()




                                                                                              Data Science  233
   230   231   232   233   234   235   236   237   238   239   240