Page 161 - Touhpad Ai
P. 161

For example:

                                   Food      Pizza     Pasta     Dosa     Chowmein     Burger   Momos

                                   People     35        30         5          25         40        15































                    Program 2: 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

                 Code:
                 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()






                                                                                                  Data Visualization  159
   156   157   158   159   160   161   162   163   164   165   166