0% found this document useful (0 votes)
9 views

Pandas- Data Visualization-Line Chart

Uploaded by

ishanvikaushal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Pandas- Data Visualization-Line Chart

Uploaded by

ishanvikaushal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

23/08/2021 Pandas- Data Visualization

Data Visualization using Matplotlib


Data visualization is the graphical representation of information and data. By using visual elements like
charts, graphs, and maps, Data visualization tools provide an accessible way to see and understand trends,
and patterns in data.

Matplotlib: Visualization with Python. Matplotlib is a comprehensive library for creating static, animated, and
interactive visualizations in Python. Matplotlib makes easy things easy and hard things possible. Use
interactive figures that can zoom, pan, update. Pyplot module in Matplotlib supports graph and plots such as
Histogram, Bar Chart etc.

Type of charts
In [ ]:

A line chart or line graph is a type of chart which displays information


as a series of data points called 'markers' connected by straight line segments.
Line graphs are usually used to find relationship
between two data sets on different axis; for instance X, Y.

In [ ]:

A bar chart or bar graph is a chart or graph that presents categorical


data with rectangular bars with heights or lengths proportional to the values that they
represent.
The bars can be plotted vertically or horizontally.

In [ ]:

A histogram shows the frequency on the vertical axis and the horizontal axis is
another dimension.
Usually it has bins, where every bin has a minimum and maximum value.
Each bin also has a frequency between x and infinite.

Plotting line chart


In [2]:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

localhost:8888/nbconvert/html/Desktop/IP 12( 21-22)/Pandas- Data Visualization.ipynb?download=false 1/6


23/08/2021 Pandas- Data Visualization

In [7]:

#line chart on these 2 lists


#plot() is the function that allows us to create line graph
list1=[2,4,6,8,10]
list2=[10,20,5,14,75]
plt.plot(list1,list2)

Out[7]:

[<matplotlib.lines.Line2D at 0x2675213ef88>]

List of Pyplot functions to customize plots


In [ ]:

legend - Place a legend on the axis.


savefig - Save the current figure.
show - Display all figures.
title - Set a title for the axis.
xlabel - Set the label for the x-axis.
ylabel - Set the label for the y-axis.

localhost:8888/nbconvert/html/Desktop/IP 12( 21-22)/Pandas- Data Visualization.ipynb?download=false 2/6


23/08/2021 Pandas- Data Visualization

In [11]:

#Line Chart with basic customisation using pyplot


list1=[2,4,6,8,10]
list2=[10,20,5,14,75]
plt.plot(list1,list2)
plt.xlabel("List1")
plt.ylabel("List2")
plt.title("Demo Chart")
plt.savefig("D:\\graphs\myimage")

In [ ]:

Line Chart – Changing Marker type, size and colour


➢ marker – specifies the type of marker
➢ markersize – It defines marker size. It is to be specified in points.
➢ markeredgecolor – specifes the colour of marker edge

localhost:8888/nbconvert/html/Desktop/IP 12( 21-22)/Pandas- Data Visualization.ipynb?download=false 3/6


23/08/2021 Pandas- Data Visualization

In [9]:

Class=['Seven','Eight','Nine','Ten','Eleven','Twelve']
number=[34,56,78,12,67,45]
Age=[13,14,15,16,17,18]
plt.plot(Class,number)
plt.plot(Class,Age)
plt.ylabel('Age/No. of students')
plt.xlabel('Class')
plt.title('No. of student age wise in class')
plt.grid(True)
plt.plot(Class,number,label="Class & no. of students", marker='<',linestyle=':',linewid
th=3,markersize=10,markeredgecolor="blue",color='green',markerfacecolor='red')
plt.plot(Class,Age, label="Class & Age", marker='o',linestyle='--',linewidth=3,markersi
ze=10,color='yellow',markerfacecolor='blue',markeredgecolor='red')
plt.legend()
plt.show()

localhost:8888/nbconvert/html/Desktop/IP 12( 21-22)/Pandas- Data Visualization.ipynb?download=false 4/6


23/08/2021 Pandas- Data Visualization

In [2]:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
name=["Sony","Zee","Aaj tak","Star Plus"]
trp=[67,78,89,60]
plt.plot(name,trp,label="Name/TRP of the channels",color="red",linestyle=":")
plt.grid(True)
plt.title("TRP of various Channels",color="red")
plt.xlabel("Name of the channels",fontsize=10,color="red")
plt.ylabel("TRP of the channels",fontsize=10,color="green")
plt.legend()
plt.show()

localhost:8888/nbconvert/html/Desktop/IP 12( 21-22)/Pandas- Data Visualization.ipynb?download=false 5/6


23/08/2021 Pandas- Data Visualization

In [4]:

import matplotlib.pyplot as p
x=[6,7,8,9,10]
y=[60,40,55,30,70]
p.plot(x,y, linestyle="dashed")
p.title('Secondary Class Strength')
p.grid(True)
p.xlabel('Class')
p.ylabel('No. of students')
p.show()

In [ ]:

localhost:8888/nbconvert/html/Desktop/IP 12( 21-22)/Pandas- Data Visualization.ipynb?download=false 6/6

You might also like