Data Visualization
Data Visualization
Numpy library is not preinstalled library so we have to install before use the
NumPy
Installation Procedure of NumPy
if already install so it will show requirement already satisfied
print(n.shape) //Shape mean dimension so in 1D array it print total number of element in form or tuple
(5,)
Example how to convert List into Double Dimension Array using Numpy
d=[[1,2,3,4],[5,6,7,8],[7,8,9,4]]
>>> num=np.array(d)
>>> print(d)
[[1, 2, 3, 4], [5, 6, 7, 8], [7, 8, 9, 4]]
>>> print(num)
[[1 2 3 4]
[5 6 7 8]
[7 8 9 4]]
>>> print(num.shape)
(3, 4) 3 Row and 4 Column
Display the Data type of array which type of element is stored in num
>>> print(num.dtype)
int32
Another way to create the Array using NumPy without list support
Arrange( ) function in NumPy it is similar to range( ) function but it return the
ndarray in place of python list
num=np.arange(1,10,2,np.int32)
Description : it will start from 1 to 10 with the gap or step 2 and all the element will be
int type
>>> print(num)
[1 3 5 7 9]
Note All three values we have to give in this last value is exclusive
num=np.arange(2, 12, 2, np.float32)
>>> print(num)
[ 2. 4. 6. 8. 10.]
Linspace( ) Some time we need evenly spaced elements between two given limits
For Example
num=np.linspace(1,20,8)
>>> print(num)
[ 1. 3.71428571 6.42857143 9.14285714 11.85714286 14.57142857
17.28571429 20. ]
It will generate the 8 value between 1 to 20 with equally space in this function first and
last value is inclusive
Example 2 of linspace
num=np.linspace(1,10,5)
>>> print(num)
[ 1. 3.25 5.5 7.75 10. ]
Matplotlib
Matplotlib helps in customizing your data plots, building 3D plots and tackling real-
world data with ease
Matplotlib is a multi-platform data visualization tool for creating advanced-level and
interactive data visualizations that showcase insights from your datasets
Line chart
Practical Constuctrion of Line Chart
import numpy as np
import matplotlib.pyplot as pl
x=[1,2,3,4]
y=[7,5,3,2]
pl.xlabel("x")
pl.ylabel("y")
pl.plot(x,y)
pl.show()---------------This function display the chart
Output
Below
After that now we can set the Line Style, Line Width, Line Color
Every modification will be done in pl.plot function
Example 2
import matplotlib.pyplot as pl
x=[1,2,3,4] Color
y=[7,6,5,4] Thickness
pl.xlabel("X-axis")
pl.ylabel("Y-axis")
pl.plot(x, y, 'r', linewidth=2, linestyle="dotted") Shape
pl.show()
Line styles
1. dashed
2. dashdot
3. solid
Colors
1. r
2. m
3. y
4. k
5. w
6. c
7. b
Marker style
The style can be set from the above table. There are different kind of markers are available
Marker Size
The size of the marker can also be set like 2 3, 4 5
Marker Edge Color
The color of the marker can be set by MarkerEdge
Example 3
import matplotlib.pyplot as pl
x=[1,2,3,4]
y=[7,6,5,4]
pl.xlabel("x-axis")
pl.ylabel("y-axis")
pl.plot(x,y,marker='+',markersize='7',markeredgecolor='red')
pl.show()
Note:
Bar Chart
How to construct the Bar chart using python programming language
Example 1 of Barchart
import numpy as np
import matplotlib.pyplot as pl
x=[1,2,3,4]
y=[7,6,5,4]
pl.xlabel("x-axis")
pl.ylabel("y-axis")
pl.bar(x,y,width=0.2) Width is the thickness of bar
pl.show()
Pie-Chart
In Pie Chart a circle is divided into sectors that each represent a proportion of
the whole.
Pie charts are generally used to show percentage or proportional data and
usually the percentage represented by each category is provided next to the
corresponding slice of pie
Pie charts are used in data handling and are circular charts divided up into
segments which each represent a value. Pie charts are divided into sections (or
'slices') to represent values of different sizes
Every slice or section represent some part or percentage of circle
Every slice or section will be display percentage form means how much percentage these slices
are occupying of entire radius
Some more values are there to show the percentage
We can set the x-limit and y-limit in the Graph how we will see
The by default values which is coming in x-axis and y-axis it can be set according
the programmer
We can save our created chart just click on the save the figure button appear in the left
hand side of Chart. It will be save in the save type of Portable Network Graphics Format(png)