Professional Documents
Culture Documents
DATA VISUALIZATION PART NOTES - 1
DATA VISUALIZATION PART NOTES - 1
Meaning : Data visualization means graphical or pictorial Representation of the data using
graph, chart, etc. The aim of plotting data is to visualize and represent relationship among
variables.
Use:
1. Communicate information effectively
2. Easy to understand data
3 Save time, energy and effort
4 To Find trend in data values
MATPLOTLIB LIBRARY
MATPLOTLIB – It is the whole python package or library used to create 2D graphs and plot by
using python scripts.
Pyplot – It is a module in matplotlib which support very wide variety of graphs and plots. It
help save images in several outputs such as png, psd, pdf etc.
Installation – Command pip install matplotlib is required to install matplotlib library in
python.
TYPES OF CHARTS
COMPONENTS OF CHART
1. Chart Title – It is heading of chart which help user to understand what the chart
represents.
2. Axis Title – It represents heading of both axes horizontal and vertical.
3. Plot area – An area containing the chart, axes and gridlines.
4. Chart area – An entire area containing the chart and all its elements.
5. Grids – These are the horizontal or vertical lines in the plot area.
6. Legend – It identifies each data series in a chart. Each data series is assigned a unique
colour to differentiate one data series from another.
LINE CHART
'.' point
'o' circle
'v' triangle_down
'^' triangle_up
'8' octagon
's' square
'p' pentagon
'*' star
'h' hexagon 1
'H' hexagon 2
'+' plus
'x' x
'X' filled x
'D' diamond
CUSTOMIZING LINE
(1) linecolor='<color abbreviation>
CUSTOMIZING TITLE/LABEL
1. fontsize = 4
2. fontcolor = ‘red’
CUSTOMIZING LEGEND
1. loc() – ‘upper right’, ‘lower right’, ‘lower left’, ‘upper left’, ‘upper center’, ‘lower center’
2. frameon=True or False
3. shadow=True or False
PROGRAM 2:
import matplotlib.pyplot as plt
sub = ['math','science','hindi','english']
marks= [24,48,46,48]
plt.plot(sub,marks,label='Marks', color = 'green', linewidth = 5, linestyle = 'dotted', marker ='D',
markersize = 5, markeredgecolor = 'red' )
grade = [10,15,20,25]
plt.plot(sub,grade,label ='Grades', marker ='o', markersize = 2, markeredgecolor = 'blue', color =
'yellow', linewidth = 5, linestyle = 'solid')
plt.xlabel('Subject',fontsize =19, color = ‘red)
plt.ylabel('Marks', fontsize=25, color = ‘green’)
plt.legend(loc = 'upper right',frameon =True, shadow = True)
plt.title('Result', fontsize = 30, color= ‘blue’)
plt.grid()
plt.show()
KIND KEYWORD
The plot() method of Pandas accepts a considerable number of arguments that can be used to
plot a variety of graphs. It allows customising different plot types by supplying the kind
keyword arguments.
The general syntax is: plt.plot(kind)
Ex. plt.plot(bar) – it will create bar chart
It means by default plot() function create line chart but with kind keyword, it can create any
type of chart.
Kind = Plot type
line Line plot (default)
bar Vertical bar plot
barh Horizontal bar plot
hist Histogram
box Boxplot
scatter Scatter plot
TICKS
Ticks are the markers which are used to show the specific points on the axis. There are two
ticks function:
(i) xticks()
(ii) yticks()
(iii) xlim() - limitation
(iv) ylim() - limitation
Ex. A program x=[10,20,30,40,50] y=[100,200,300,400,500]
Program generate range according itself.
500
450
400
350
300
250
200
150
100
50
0
10 15 20 25 30 35 40 45 50
On using xticks() -
plt.xticks(x,[10,20,30,40,50])
plt.yticks(y,[100,200,300,400,500])
Program generate range according ticks.
500
400
300
200
100
0
10 20 30 40 50
Ex.
plt.xlim([0,500])
plt.ylim([10,50])
Multiple chart in single window
Subplot(arg1,arg2,arg3)
Arg1=row, arg2=column, arg3= plot no.
Ex. Subplot(2,1,1) means chart will ready in two rows(up-down) with 1 column and for 1st
chart.
Subplot(1,2,1) means chart will ready in two columns(left-right) with 1row and for 1st chart
PROGRAM 1. Multiple plot in same window
import matplotlib.pyplot as plt
x=[1,2,3,4]
y=[2,4,6,8]
plt.subplot(2,1,1)
plt.plot(x,y)
x=(10,20,30,40)
y=(20,40,60,80)
plt.subplot(2,1,2)
plt.plot(x,y)
plt.show()