Introduction to Data Visualization

Amit kumar
Analytics Vidhya
Published in
3 min readJan 6, 2021

--

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, outliers, and patterns in data.

Matplotlib

Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2002.

One of the greatest benefits of visualization is that it allows us visual access to huge amounts of data in easily digestible visuals. Matplotlib consists of several plots like line, bar, scatter, histogram etc.

Matplotlib Installation

python -m pip install -U matplotlib

Importing Matplotlib

from matplotlib import pyplot as plt
or
import matplotlib.pyplot as plt

Basic plots in Matplotlib

Matplotlib comes with a wide variety of plots. Plots helps to understand trends, patterns, and to make correlations. They’re typically instruments for reasoning about quantitative information. Some of the sample plots are covered here.

Getting Started

import matplotlib.pyplot as plt
import numpy as np
xpoints=np.array([0,5])
ypoints=np.array([0,250])
plt.plot(xpoints,ypoints)
plt.show()
#draw a line from position (1,3) to (1,8)
xpoints=np.array([1,8])
ypoints=np.array([3,10])
plt.plot(xpoints,ypoints)
plt.show()
#plotting without line
#draw two points one at(1,3) and one at(8,10)
xpoints=np.array([1,8])
ypoints=np.array([3,10])
plt.plot(xpoints,ypoints,'o')
plt.show()
#multiple points 
xpoints=np.array([2,4,5,8])
ypoints=np.array([3,7,1,5])
plt.plot(xpoints,ypoints)
plt.show()
#if we do not specify x-axis then defaukt value is 0,1,2,3,etc.
ypoints=np.array([3,8,1,10,5])
plt.plot(ypoints)
plt.show()
#marker at each point
ypoints=np.array([3,8,1,10,5])
plt.plot(ypoints,marker='o')
plt.show()
ypoints=np.array([3,8,1,10,5])
plt.plot(ypoints,marker='*')
plt.show()
#format string
ypoints=np.array([3,8,1,10,5])
plt.plot(ypoints, 'o:r') #dotted line :
plt.show()
ypoints=np.array([3,8,1,10,5])
plt.plot(ypoints,'o-b') #solid line
plt.show()
ypoints=np.array([3,8,1,10,5])
plt.plot(ypoints,'o--b') #dashed line
plt.show()

--

--

Amit kumar
Analytics Vidhya

I am Amit kumar from Mathura. Now I am perusing in B.tech 3rd year in BSA Engineering College. I am writing the belogs that is related to new technologies.