Page 106 - Informatics_Practices_Fliipbook_Class12
P. 106

Marker Colors

        Matplotlib also provides a range of colors to customize the appearance of markers, for example:
                                                         Table 3.2
                                            Marker Colors                   Symbol
                                                Blue                          ('b')
                                                Green                         ('g')
                                                 Red                          ('r')
                                                Cyan                          ('c')
                                               Magenta                        ('m')
                                                Yellow                        ('y')
                                                Black                         ('k')
                                                White                         ('w')

        3.1.2 Displaying a Line Joining the Points
        To display a line plot, we need to provide two lists—one containing the x-coordinates of the points to be included in
        the plot, and the other containing the y-coordinates of the corresponding points. Suppose, we wish to plot time along
        the x-axis and velocity along the y-axis, then we need to construct two lists: time and velocity, representing the
        x and y coordinates of the data points that will be plotted on the line graph. The method plt.plot() enables us to
        create line plots by connecting these points with line segments (Fig 3.2), as demonstrated below:
         >>> import matplotlib.pyplot as plt
         >>> time = [2, 4, 6, 8, 10]
         >>> velocity = [30, 40, 60, 35, 10]
         >>> plt.plot(time, velocity)
         >>> plt.show()





















                                                  Fig 3.2: Line joining points

        Line Styles

        Matplotlib offers several line styles that can be used to customize the appearance of lines in plots, as shown below:
                                                         Table 3.3
                     Line Styles                                        Description
          Solid Line Style ('-')            The solid line style represents a continuous line connecting the points.
          Dashed Line Style ('--')          The dashed line style displays a line with short dashes.
          Dash-Dot Line Style ('-.')        The dash-dot line style combines short dashes and dots to create a pattern.
          Dotted Line Style (':')           The dotted line style represents a line composed of small dots.

        Now, we plot velocity against time one more time using red colored dotted lines, and use asterisks to mark the end
        points of the line segments.

          92   Touchpad Informatics Practices-XII
   101   102   103   104   105   106   107   108   109   110   111