You are on page 1of 5

28/08/2021 AP19110010030_Assiggnmnet-3 - Jupyter Notebook

Kilaru Sravan

AP19110010030

CSE-A

Matplot Library
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

In [2]:

import pandas as pd

In [3]:

# reading data which is in csv


df=pd.read_csv('ipl.csv')
df #prints the data in csv file
Out[3]:

batsman total_runs out numberofballs average strikerate

0 V Kohli 5426 152 4111 35.697368 131.987351

1 SK Raina 5386 160 3916 33.662500 137.538304

2 RG Sharma 4902 161 3742 30.447205 130.999466

3 DA Warner 4717 114 3292 41.377193 143.286756

4 S Dhawan 4601 137 3665 33.583942 125.538881

... ... ... ... ... ... ...

511 ND Doshi 0 1 13 0.000000 0.000000

512 J Denly 0 1 1 0.000000 0.000000

513 S Ladda 0 2 9 0.000000 0.000000

514 V Pratap Singh 0 1 1 0.000000 0.000000

515 S Kaushik 0 1 1 0.000000 0.000000

516 rows × 6 columns

localhost:8888/notebooks/AP19110010030_Assiggnmnet-3.ipynb 1/5
28/08/2021 AP19110010030_Assiggnmnet-3 - Jupyter Notebook

In [5]:

import matplotlib.pyplot as plt

Histogram
A histogram is used to display the distribution of information or data over a continuous time period.
Histograms may have a similar appearance to bar charts but unlike them, are used to plot the frequency of
variable occurrences in continuous data and this continuous data is divided into classes called bins.
A histogram is used to display continuous data in a categorical form.
In a histogram, there are no gaps between the bars, unlike a bar graph.

In [8]:

plt.hist(df["out"])
plt.xlabel("No.of outs")
plt.ylabel("No.of players")
plt.show()

Pie chart
Pie Charts help show proportions and percentages between categories, by dividing a circle into
proportional segments.
Each arc length represents a proportion of each category, while the full circle represents the total sum of all
the data, equal to 100%.
A Pie Chart can only display one series of data. Pie charts show the size of items (called wedge) in one
data series,proportional to the sum of the items.
Matplotlib API has a pie() function that generates a pie diagram representing data in an array. The
fractional area of each wedge is given by x/sum(x).

localhost:8888/notebooks/AP19110010030_Assiggnmnet-3.ipynb 2/5
28/08/2021 AP19110010030_Assiggnmnet-3 - Jupyter Notebook

In [11]:

plt.pie(df["total_runs"][:10],labels = df["batsman"][:10], autopct = "% 1.1f%%")


plt.show()

Box plot
A box plot visualization allows you to examine the distribution of data.
Each box plot displays the minimum, first quartile, median, third quartile, and maximum values.
In addition, you can choose to display the mean and standard deviation as dashed lines and outliers
appear as points in the visualization.

In [12]:

plt.boxplot(df["total_runs"])
plt.show()

Scatter plot
localhost:8888/notebooks/AP19110010030_Assiggnmnet-3.ipynb 3/5
28/08/2021 AP19110010030_Assiggnmnet-3 - Jupyter Notebook

A scatter plot is a type of data visualization that shows the relationship between different variables.
Scatter plots can also be known as scatter diagrams or x-y graphs, and the point of using one of these is to
determine if there are patterns or correlations between two variables.
The dots in a scatter plot not only report the values of individual data points, but also patterns when the
data are taken as a whole
Identification of correlational relationships are common with scatter plots.

In [14]:

plt.scatter(df["out"][:10],df["batsman"][:10])
plt.xlabel("no.of out")
plt.ylabel("Player name")
plt.show()

Column chart
Column Charts are used for showing data changes over a period of time or for illustrating comparison
among items.
In Column Charts, categories are along the horizontal axis and values along the vertical axis.
Column charts are typically used to compare several items in a specific range of values.
Column charts are ideal if you need to compare a single category of data between individual sub-items
Column charts work well in showing data changes over a period of time by displaying the comparisons
among subjects on an overall chart.

localhost:8888/notebooks/AP19110010030_Assiggnmnet-3.ipynb 4/5
28/08/2021 AP19110010030_Assiggnmnet-3 - Jupyter Notebook

In [19]:

plt.bar(df["batsman"][:5],df["out"][:5],color = "c", width = 0.4)


plt.xlabel("Nmae of batsman")
plt.ylabel("total out")
plt.show()

localhost:8888/notebooks/AP19110010030_Assiggnmnet-3.ipynb 5/5

You might also like