Page 205 - Robotics and AI class 10
P. 205

Colours
            We can either use character codes or the color names as values to the parameter color in the plot().

                                               Character                 Colour
                                                  'b'                      blue
                                                  'g'                     green
                                                   'r'                     red
                                                  'c'                      cyan

                                                  'm'                    magenta
                                                  'y'                     yellow
                                                  'k'                     black
                                                  'w'                     white
            Linewidth and Line Style

            The linewidth is given in pixels. The default is 1 pixel. You can increase the number to increase the width.
            Linestyle can be "solid", "dotted", "dashed" or "dashdot".
            Let us now make some graphs :
            Plotting a Line Chart

               • Single line chart
               import matplotlib.pyplot as plt

              city=['Delhi','Mumbai','Chennai','Kolkata']
              temp=[35,21,40,22]
              plt.xlabel('Metro Cities')
              plt.ylabel('Temp in Celsius')

              plt.title('Temperature Study of the Day')
              plt.plot(city,temp,marker='*',markersize=10,color='red',
                        linewidth=2, linestyle='dashdot')
              plt.show()
            The above code will create a line graph as shown below:
                                                      Temperature Study of the Day
                                        40.0                            

                                        37.5
                                        35.0 
                                       Temp in Celsius  30.0
                                        32.5



                                        27.5
                                        25.0

                                        22.5                                          
                                                           
                                            Delhi        Mumbai        Chennai      Kolkata
                                                             Metro Cities


                                                         Introduction to Data and Programming with Python  203
   200   201   202   203   204   205   206   207   208   209   210