Page 206 - Robotics and AI class 10
P. 206
• Multiple line chart
import matplotlib.pyplot as plt
city=['Delhi','Mumbai','Chennai','Kolkata']
day1=[35,21,40,22]
day2=[30,25,36,20]
day3=[24,29,42,24]
plt.xlabel('Metro Cities')
plt.ylabel('Temp in Celsius')
plt.title('Temperature Study of the Day')
plt.plot(city, day1)
plt.plot(city, day2)
plt.plot(city, day3)
plot.show()
The above code will create a multiple line graph as shown below:
Temperature Study of the Day
40
35
Temp in Celsius 30
25
20
Delhi Mumbai Chennai Kolkata
Metro Cities
Plotting a bar chart
It is used to plot data using rectangular bars or columns. It is generally used to compare values of two different
categories. Example: marks of 5 subjects to compare, rise in population in five years,changing fuel price every
month.
Various versions of bar charts exist like single bar chart, double bar chart, etc. can be used.
Matplotlib uses a built-in function - bar () and plot() to create bar charts.
● Using bar()
# Data for the x-axis and y-axis
city=['Delhi','Mumbai','Chennai','Kolkata']
day1=[35,21,40,22]
# Creating the bar chart
plt.bar(city, day1)
# Adding labels and title
204 Touchpad Robotics & Artificial Intelligence-X

