Page 298 - Ai_V3.0_c11_flipbook
P. 298

Program 6: Create a Bar Graph for, how many people like varied food items using Python.


                               Food              Pizza     Burger     Momos     Chowmein       Pasta
                               No. of People      30         24         36          40          28




              import matplotlib.pyplot as plt


              # Sample data for the bar chart
              food_types = ['Pizza', 'Burger', 'Momos', 'Chowmein', 'Pasta']
              values = [30, 24, 36, 40, 28]


              # Create a bar chart using bar() function with customized width
              plt.bar(food_types, values, color='skyblue', edgecolor='black', width=0.5)


              # Add titles and labels
              plt.title('Popularity of Different Types of Food')
              plt.xlabel('Food Type')

              plt.ylabel('Number of People')


              # Display the plot
              plt.show()
              Output:


























              The various attributes used in the above program are:
                 • color – sets the bar colour

                 • edgecolor – sets the colour of the bar edges
                 • width – sets the width of the bars

              Histogram
              Histogram is a form of bar graph. It is a visualisation of several outcomes organised into columns along the x-axis. The
              y-axis of the histogram represents the number count or multiple occurrences in the data for each column.

                    296     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   293   294   295   296   297   298   299   300   301   302   303