Unit 1 - Chap 2 - Data Visualisation
Unit 1 - Chap 2 - Data Visualisation
Importing PyPlot
import matplotlib.pyplot
This would required you to refer to every command of pyplot as
matplotlib.pyplot.<command>
1. Line chart
It is a type of chart which displays
information as series of data points called ‘markers’
connected by straight line segments.
plt.plot(week, prices)
plt.xlabel("Week")
plt.ylabel("Onion prices (Rs.)")
plt.show()
plt.xlabel("Overs")
plt.ylabel("Runs per over")
plt.title("T50 World Cup")
plt.show()
Designed by: Umesh Pun (PGT IP) APS Yol Cantt
Example (Line chart)
import matplotlib.pyplot as plt
year=[2015,2016,2017,2018,2019,2020]
x=[90,92,94,95,97,85]
xii=[89,90,93,85,95,98]
plt.plot(year,x,color='g')
plt.plot(year,xii,color='orange')
plt.xlabel('Year')
plt.ylabel('Passpercentage')
plt.title('Pass% till 2020')
plt.legend(('x','xii'), loc='upper right')
plt.show()
plt.savefig('line_plot.pdf')
2. Bar chart
plt.bar(week, prices)
plt.show()
plt.title("Olympics")
plt.xlabel("Medal type")
plt.ylabel("Medal count")
plt.show()
plt.title("Olympics")
plt.xlabel("Medal type")
plt.ylabel("Medal count")
plt.show()
plt.bar(medal, india)
plt.bar(medal, china)
plt.title("Olympics")
plt.xlabel("Medal type")
plt.ylabel("Medal count")
plt.show()
index = np.arange(len(label))
plt.bar(index, per)
plt.xlabel('Student Name', fontsize=5)
plt.ylabel('Percentage', fontsize=5)
plt.xticks(index, label, fontsize=5, rotation=30)
plt.title('Percentage of Marks achieve by student Class XII')
plt.legend(('Name','Per'), loc='upper right')
plt.show()
x = [1,1,2,3,3,5,7,8,9,10,
10,11,11,13,13,15,16,17,18,18,
18,19,20,21,21,23,24,24,25,25,
25,25,26,26,26,27,27,27,27,27,
29,30,30,31,33,34,34,34,35,36,
36,37,37,38,38,39,40,41,41,42,
43,44,45,45,46,47,48,48,49,50,
51,52,53,54,55,55,56,57,58,60,
61,63,64,65,66,68,70,71,72,74,
75,77,81,83,84,87,89,90,90,91]
plt.show()
plt.show()