Page 319 - AI_Ver_3.0_class_11
P. 319

2.   You ask your friends which ‘food item’ they like best. Here is what you found:
                                Pizza          Burger         Momos           Rolls       French Fries
                                  3              5               6              2              4
                           Create a pie chart of the above data and answer the following questions after studying the graph.
                           i)  Which food item is liked the most?

                           ii)  Which food item is liked the least?
                           iii)  Which food items together constitute 50% of the graph?
                       Ans.
                           import matplotlib.pyplot as plt
                           # Data
                           labels = ['Pizza', 'Burger', 'Momos', 'Rolls', 'French Fries']
                           sizes = [3, 5, 6, 2, 4]
                           colors = ['gold', 'lightcoral', 'lightskyblue', 'lightgreen', 'orange']
                           explode = (0.1, 0, 0, 0, 0)  # explode the 1st slice (Pizza)
                           # Create pie chart
                           plt.pie(sizes, explode=explode, labels=labels, colors=colors,
                                   autopct='%1.1f%%', shadow=True, startangle=140)
                           # Add title
                           plt.title('Food Preference')
                           # Equal aspect ratio ensures that pie is drawn as a circle.
                           plt.axis('equal')
                           # Show plot
                           plt.show()
                           i)  Momos
                           ii)  Rolls
                           iii)  Momos & French Fries





















                                                                   Data Literacy—Data Collection to Data Analysis  317
   314   315   316   317   318   319   320   321   322   323   324