Data_visualization.ipynb - Colaboratory
Data_visualization.ipynb - Colaboratory
ipynb - Colaboratory
Matplotlib
Matplotlib is a python library used to create 2D graphs and plots by using python scripts. It has a module named pyplot which makes things
easy for plotting by providing feature to control line styles, font properties, formatting axes etc. It supports a very wide variety of graphs and
plots namely - histogram, bar charts, power spectra, error charts etc.
Line charts are used to represent the relation between two data X and Y on a different axis. Linestyle (ls) can be:
1. solid(default) = '-'
2. dotted = ':'
3. dashed = '--'
4. dashdot = '-.'
5. None = '' or ' '
You can use the keyword argument color or the shorter c to set the color of the line and keyword argument linewidth or the shorter lw to change
the width of the line. The value is a floating number, in points.
account_circle
y1 = np.array([3, 8, 1, 10])
y2 = np.array([6, 2, 7, 11])
plt.plot(y1)
plt.plot(y2)
plt.show()
https://colab.research.google.com/drive/1k7wTRcIzikqx-HetuXk5asNrGqpZ-vct#printMode=true 1/4
18/11/2023, 19:11 Data_visualization.ipynb - Colaboratory
A bar plot or bar chart is a graph that represents the category of data with rectangular bars with lengths and heights that is proportional to the
values which they represent. The bar plots can be plotted horizontally or vertically. A bar chart describes the comparisons between the discrete
categories. One of the axis of the plot represents the specific categories being compared, while the other axis represents the measured values
corresponding to those categories.
The bar() function takes arguments that describes the layout of the bars. The categories and their values represented by the first and second
argument as arrays.
If you want the bars to be displayed horizontally instead of vertically, use the barh() function
import numpy as np
import matplotlib.pyplot as plt
plt.bar(x,y,width=0.4)
plt.show()
https://colab.research.google.com/drive/1k7wTRcIzikqx-HetuXk5asNrGqpZ-vct#printMode=true 2/4
18/11/2023, 19:11 Data_visualization.ipynb - Colaboratory
A histogram is basically used to represent data provided in a form of some groups.It is accurate method for the graphical representation of
numerical data distribution.
plt.hist(x)
plt.show()
A Pie Chart is a circular statistical plot that can display only one series of data. The area of the chart is the total percentage of the given data.
The area of slices of the pie represents the percentage of the parts of the data. The slices of pie are called wedges. The area of the wedge is
determined by the length of the arc of the wedge.
Add labels to the pie chart with the label parameter. The label parameter must be an array with one label for each wedge
https://colab.research.google.com/drive/1k7wTRcIzikqx-HetuXk5asNrGqpZ-vct#printMode=true 3/4
18/11/2023, 19:11 Data_visualization.ipynb - Colaboratory
Scatter plots are used to observe relationship between variables and uses dots to represent the relationship between them. The scatter()
method in the matplotlib library is used to draw a scatter plot. Scatter plots are widely used to represent relation among variables and how
change in one affects the other. You can set your own color for each scatter plot with the color or the c argument
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y, color='cyan')
plt.show()
https://colab.research.google.com/drive/1k7wTRcIzikqx-HetuXk5asNrGqpZ-vct#printMode=true 4/4