Page 211 - Robotics and AI class 10
P. 211
Brainy Fact
You may create a figure with many plots known as subplots side by side sharing either the same x
axis or same y axis. Following is the code to create 3 subplots with shared y axis
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True)
Plotting a Pie chart
It is a circular representation of data where each slice shows the relative size of the data.The data is a complete
circle equal to 360°with each segment and sectors forming a certain portion of the total(percentage).
Matplotlib uses a built-in function - pie() to create pie charts.
Pie chart represents a circle divided into different sectors where each sector represents a part of the whole. A pie
plot is used to represent numerical data proportionally.
import matplotlib.pyplot as plt
# Data for the pie chart
Temp = [20, 30, 15, 10, 25]
Cities = ['Pune', 'Banglore', 'Jammu', 'Srinagar'. 'Mumbai']
#Creating the pie chart
plt.pie(temp, labels=Cities, autopct]'%1.if%%')
# Adding title
plt.title('Pie chart')
# Displaying the pie chart
plt.show()
Pie Chart
Bengaluru
Pune
30.0%
20.0%
15.0%
Jammu 25.0%
10.0%
Mumbai
Srinagar
Let us do the following question:
Suppose you conducted a survey to determine the favourite genres of music among a group of students in your
school. The results of the survey are as follows: 30% prefer Pop, 25% prefer Rock, 15% prefer Hip Hop, 20% prefer
Country, and 10% prefer Jazz. Design a pie chart to visually represent these survey results."
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'Music':[30, 25, 15, 20, 10],}
index['Pop', 'Rock', 'Hip Hop', 'Country', 'Jazz'])
Introduction to Data and Programming with Python 209

