Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

DATA VISUALIZATION

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

List of Pyplot functions to customize plots


1. grid - Configure the grid lines.
Ex: plt.grid(True): shows grid line NOTE: By default grid turned on - plt.grid()
2. title - Set a title for the axes.
Ex: plt.title(“Title name”)
3. Adding labels:
a) xlabel - Set the label for the x-axis. Ex. plt.xlabel(“ x axis label name”)
b) ylabel - Set the label for the y-axis. Ex. plt.ylabel(“y axis label”)
4. legend - Place a legend on the axes.
Ex: plt.legend()
5. savefig - Save the current figure.
Ex: plt.savefig(“ path&filename”)
6. show - Display the chart.
Ex: plt.show()
SIMPLE LINE CHART – PROGRAM
import matplotlib.pyplot as plt
Student = [abhi,kapil,rajesh,vinay]
Age = [6,10,14,13]
plt.plot(student,age)
plt.title(" MY first Line chart")
plt.xlabel("Student")
plt.ylabel("Age")
plt.show()
CUSTOMIZING LINE CHART
1. plot() function is used to create line chart. Syntax – plt.plot()
2. Attributes of plot()
(i) x value
(ii) y value
(iii) label
(iv) line
(v) Marker - A marker is any symbol that represents a data value in a line chart
CUSTOMIZING MARKER
(1) markeredgecolor='<color abbreviation>
color ='<color Color Name
(2) markerfacecolor='<color abbreviation> abbreviation>'
'b' blue
(3) markersize=<float or int>
'c' cyan
(4) marker = <marker abbreviation > 'g' green
'k' black
'm' magenta
'r' red
'w' white
'y' yellow
Marker
Marker Style
Abbreviation

'.' point

',' one pixel

'o' circle

'v' triangle_down

'^' triangle_up

'8' octagon

's' square

'p' pentagon

'*' star

'h' hexagon 1

'H' hexagon 2

'+' plus

'P' filled plus

'x' x

'X' filled x

'D' diamond

'd' thin diamond

CUSTOMIZING LINE
(1) linecolor='<color abbreviation>

(2) linesize=<float or int>

(3) linestyle = <line abbreviation >


linestyle='<style Line Style
abbreviation>'
'-' or 'solid' solid line (default)
'--' or 'dashed' dashed line
'-.' or 'dashdot' dash-dot line
':' or 'dotted' dotted line
'None' or ' ' or '' no line

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()

PROGRAM 2. Multiple plot in same window


import matplotlib.pyplot as plt
x=[1,2,3,4]
y=[2,4,6,8]
plt.subplot(1,2,1)
plt.plot(x,y)
x=(10,20,30,40)
y=(20,40,60,80)
plt.subplots_adjust(hspace=2, wspace =2)
plt.subplot(1,2,2)
plt.plot(x,y)
plt.show()

You might also like