0% found this document useful (0 votes)
20 views2 pages

Eda Lab-Unit-Ii-4

EDSA-PYTHON LAB

Uploaded by

arafaths062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Eda Lab-Unit-Ii-4

EDSA-PYTHON LAB

Uploaded by

arafaths062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

EDA LAB

UNIT-II

4.Generate the following charts for a dataset.


a) Polar Chart b)Histogram c)Lollipop chart
a) Polar Chart
A polar chart is a diagram that is plotted on a polar axis. Its coordinates are angle and
radius, as opposed to the Cartesian system of x and y coordinates. Sometimes, it is
also referred to as a spider web plot.

#Let's assume you have five courses in your academic year:


subjects = ["C programming", "Numerical methods", "Operating
system", "DBMS", "Computer Networks"]
#And you planned to obtain the following grades in each subject:
plannedGrade = [90, 95, 92, 68, 68, 90]
#However, after your final examination, these are the grades you got:
actualGrade = [75, 89, 89, 80, 80, 75]

The first significant step is to initialize the spider plot. This can be done by setting
the figure size and polar projection.

#Import the required libraries:


import numpy as np
import matplotlib.pyplot as plt
# Prepare the dataset and set up theta:
theta = np.linspace(0, 2 * np.pi, len(plannedGrade))

#Initialize the plot with the figure size and polar projection:
plt.figure(figsize = (10,6))
plt.subplot(polar=True)
#Get the grid lines to align with each of the subject names:
(lines,labels) = plt.thetagrids(range(0,360,
int(360/len(subjects))),
(subjects))
#Use the plt.plot method to plot the graph and fill the area under it:
plt.plot(theta, plannedGrade)
plt.fill(theta, plannedGrade, 'b', alpha=0.2)
#Now, we plot the actual grades obtained:
plt.plot(theta, actualGrade)
#We add a legend and a nice comprehensible title to the plot:
plt.legend(labels=('Planned Grades','Actual Grades'),loc=1)
plt.title("Plan vs Actual grades by Subject")
#Finally, we show the plot on the screen:
plt.show()

b)Histogram
Histogram plots are used to depict the distribution of any continuous variable. These
types of plots are very popular in statistical analysis.

import matplotlib.pyplot as plt


import numpy as np
x = np.random.normal(170, 10, 250)
plt.hist(x)
plt.show()

c)Lollipop chart
They are nothing but a variation of the bar chart in which the thick bar is replaced
with just a line and a dot-like “o” (o-shaped) at the end. Lollipop Charts are preferred
when there are lots of data to be represented that can form a cluster when represented
in the form of bars.

Python allows to build lollipops, thanks to the matplotlib library, as shown in


the examples below. The strategy here is to use the stem() function.
A lollipop plot displays each element of a dataset as a segment and a circle.

# Create a dataframe
import pandas as pd
df = pd.DataFrame({'group':list(map(chr, range(65, 85))),
'values':np.random.uniform(size=20) })

# Reorder it following the values:


ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)

# Make the plot


plt.stem(ordered_df['values'])
plt.xticks( my_range, ordered_df['group'])

CONCLUSIONS:

You might also like