Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Data_visualization.ipynb - Colaboratory

The document provides an overview of data visualization using the Matplotlib library in Python, detailing various types of plots including line charts, bar charts, histograms, pie charts, and scatter plots. It includes code examples for each plot type, demonstrating how to customize features such as line style, color, and width. The document serves as a practical guide for creating visual representations of data using Matplotlib.

Uploaded by

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

Data_visualization.ipynb - Colaboratory

The document provides an overview of data visualization using the Matplotlib library in Python, detailing various types of plots including line charts, bar charts, histograms, pie charts, and scatter plots. It includes code examples for each plot type, demonstrating how to customize features such as line style, color, and width. The document serves as a practical guide for creating visual representations of data using Matplotlib.

Uploaded by

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

18/11/2023, 19:11 Data_visualization.

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.

import matplotlib.pyplot as plt


import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, linestyle = 'dotted', color = 'r', linewidth = '4.2')


plt.show()

account_circle

#multiple plots on the same axis


import matplotlib.pyplot as plt
import numpy as np

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

x = np.array(["A", "B", "C", "D"])


y = np.array([3, 8, 1, 10])

plt.bar(x,y,width=0.4)
plt.show()

plt.barh(x,y, height = 0.4, color='red')


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.

import matplotlib.pyplot as plt


import numpy as np

x = np.random.normal(170, 10, 250)

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

import matplotlib.pyplot as plt


import numpy as np

y = np.array([35, 25, 25, 15])


mylabels = ["Apples", "Bananas", "Cherries", "Dates"]

plt.pie(y, labels = mylabels)


plt.show()

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

import matplotlib.pyplot as plt


import numpy as np

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

You might also like