Data Visualization
Data Visualization
matplotlib Introduction
Python supports a variety of packages to handle data. Matplotlib is
also one of the most important packages out of them. It is a
low-level library integrated with a Matlab-like interface that offers
few lines of code and draws graphs or charts. It has modules such
as a pyplot to draw and create graphs.
In the next section of Comprehensive notes Data Visualization
Class 12 IP you will know the steps required to create a chart.
Output:
Line plot in Python 3.8.3
In the above code, 3 subject marks are plotted on the figure. The
navigation toolbar helps to navigate through the graph. Now
observe the following code for plotting multiple lines on the graph.
import matplotlib.pyplot as mpp
o=[5,10,15,20]
r_india=[30,80,120,200]
mpp.plot(o,r_india,'Red')
r_aust=[25,85,100,186]
mpp.plot(o,r_aust,'Yellow')
mpp.xlabel('Runs')
mpp.ylabel('Overs')
mpp.title('Match Summary')
mpp.show()
Output:
So now you understand how to plot lines on the figure. You can
change the colour using abbreviations and line style by using the
linestyle parameter also. Just do the following changes in
above-given code and see the output:
mpp.plot(o,r_india,’m’,linestyle=’:’)
mpp.plot(o,r_aust,’y’,linestyle=’-.’)
This section of this article Comprehensive notes Data Visualization
Class 12 IP talks about bar graphs.
Bar Graph
The bar graph represents data in horizontal or vertical bars. The
bar() function is used to create a bar graph. It is most commonly
used for 2D data representation. Just have a look at the following
code:
import matplotlib.pyplot as mpp
overs=[5,10,15,20]
runs=[30,80,120,200]
mpp.bar(runs,overs,width=30,
label='Runs',colour='r')
mpp.xlabel('Runs')
mpp.ylabel('Overs')
mpp.title('Match Summary')
mpp.legend()
mpp.show()
Output: