Page 492 - AI Ver 3.0 class 10_Flipbook
P. 492

4.  Write a program to display line chart from (2,5) to (9,10).

               Ans.  [1]:  import matplotlib.pyplot as plt
                           import numpy as np
                           # Define X and Y variable data
                           x = np.array([2,3,9,10])
                           y = x*2
                           plt.plot(x, y)
                           plt.xlabel("X-axis")  # add X-axis label
                           plt.ylabel("Y-axis")  # add Y-axis label
                           plt.title("Line Chart")  # add title
                           plt.show()
                                               Line Chart
                              20
                              18

                              16
                             Y-axis 14
                              12
                              10
                              8
                              6
                              4
                                  2   3   4    5   6    7   8    9   10
                                                 X-axis

                5.  Write a program to display a scatter chart for the following points (2,5), (9,10),(8,3),(5,7),(6,18).
              Ans.   [1]:  import matplotlib.pyplot as plt
                           import numpy as np
                           (2,5), (9,10),(8,3),(5,7),(6,18)
                           x = np.array([2,9,8,5,6])
                           y = np.array([5,10,3,7,18])
                           plt.xlabel("X-axis")  # add X-axis label
                           plt.ylabel("Y-axis")  # add Y-axis label
                           plt.title("Scatter Chart")  # add title
                           plt.scatter(x, y)
                           plt.show()
                                             Scatter Chart
                             18
                             16

                             14
                             Y-axis 12
                             10
                             8

                             6
                             4
                                 2    3    4    5    6    7     8    9
                                                 X-axis



                    490     Touchpad Artificial Intelligence (Ver. 3.0)-X
   487   488   489   490   491   492   493   494   495   496   497