Page 234 - AI Ver 1.0 Class 10
P. 234

Data Visualisation in Python


              The graphical representation of the data in a data set to identify patterns and trends out of it is called data
              visualisation. Data visualisation is part of data exploration, which is a critical step in the AI Project Cycle. We
              use this technique to gain understanding and insights to the data gathered through different sources, and
              determine if the data is ready for further processing or if you need to collect more data or clean the data.

              Matplotlib is used for data visualisation in Python. We now know what Matplotlib is and what different kinds of
              graphs are there to represent data. Now we will create them using Matplotlib.

              First, we have to load Matplotlib to start plotting different graphs:
                   import matplotlib.pyplot as plt


              Scatter Plot
              Scatter plot uses dots to display values from two variables in a graph. It is used to plot data which has no
              continuity (non-continuous data). This allows us to see if there is any relationship or correlation between the
              two variables.

              Matplotlib uses a built-in function scatter() to create scatterplots. For example,

                   import matplotlib.pyplot as plt
                   marks1 = [31,34,36,42,40,23,39]
                   marks2 = [34,45,23,44,12,16,35]
                   plt.scatter(marks1, marks2, c=‘red’)
                   plt.title(‘Scatter plot’)
                   plt.xlabel(‘marks 1’)
                   plt.ylabel(‘makrs 2’)
                   plt.show()
              Output will be:

                                                                 Scatter plot
                                           45
                                           45

                                           35
                                         marks 2  30

                                           25
                                           20

                                           15


                                             22.5 25.0  27.5 30.0 32.5 35.0 37.5 40.0 42.5
                                                               marks 1

              Bar Chart

              Bar chart is used to plot data using rectangular bars or columns. It is generally used to compare values of two
              different categories.



                        232   Touchpad Artificial Intelligence-X
   229   230   231   232   233   234   235   236   237   238   239