0% found this document useful (0 votes)
6 views6 pages

Data Visualization with Matplotlib

Uploaded by

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

Data Visualization with Matplotlib

Uploaded by

maneabhishek96
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DATA VISUALIZATION USING MATPLOTLIB

Dataset: [Link]

# line plot
import [Link] as plt
import pandas as pd

data = pd.read_csv("C://Users/Nageshwara Rao/Desktop/9-data-visualization/[Link]")


print([Link]())
x = data['marks']
y = data['rank']

[Link](x, y, color='orange')
[Link]()

# line plot and scatter plot


import [Link] as plt
import pandas as pd

data = pd.read_csv("C://Users/Nageshwara Rao/Desktop/9-data-visualization/[Link]")


print([Link]())

x = data['marks']
y = data['rank']

# draw both the plots


[Link](x, y, color='orange', label= 'line plot')
[Link](x, y, color='blue', label='scatter plot')
[Link]()

[Link]('marks', color='red')
[Link]('rank', color='red')
[Link]('MARKS VS RANKS', color='green')

[Link]()

# bar graph
import [Link] as plt
import pandas as pd

data = pd.read_csv("C://Users/Nageshwara Rao/Desktop/9-data-visualization/[Link]")

x = data['marks']
y = data['rank']

# draw bar graph, use ‘barh’ for horizontal bar graph


[Link](x, y, color='orange', label= 'bar graph')

[Link]('marks', color='red')
[Link]('rank', color='red')
[Link]('MARKS VS RANKS', color='green')

[Link](700, 1000)
[Link](2000, 2100)
[Link]()

# pie chart
import [Link] as plt
import pandas as pd

data = pd.read_csv("C://Users/Nageshwara Rao/Desktop/9-data-visualization/[Link]")

x = data['marks']

# how many got marks above 950


x1 = len(x[x>950])

# how many got marks from 850 to 950


x2 = len(x[(x>=850) & (x<=950)])

# how many got marks from 750 to 850


x3 = len(x[(x>=750) & (x<=850)])

print(x1, x2, x3)


slices = [x1,x2,x3]
cols = ["Yellow", "Red", "Green"]
lbls = ["Above 950", "850-950", "750-850"]

[Link](slices, colors= cols, labels=lbls, startangle=90,


shadow=True,
explode= (0, 0.2, 0),
autopct='%.1f%%'
)

[Link]()

# sub plots
import [Link] as plt
import pandas as pd

data = pd.read_csv("C://Users/Nageshwara Rao/Desktop/9-data-visualization/[Link]")

x = data['marks']
y = data['rank']
z = data['admit']
fig = [Link]()

graph1 = fig.add_subplot(2,2, 1, facecolor= "yellow")


[Link](x, y)
graph1.set_title('marks vs rank')

graph2 = fig.add_subplot(2,2, 2, facecolor= "cyan")


[Link](x, z)
graph2.set_title('marks vs admit')

# highest marks
x = max(x)

# lowest rank
y = min(y)

# no. of people admitted


z = len(z[z==1])

print(x,y,z)

graph3 = fig.add_subplot(2,2, 3, facecolor= "lightgreen")


[Link]("equal")
[Link]([x, y, z], colors=["Yellow", "Red", "Green"])
graph3.set_title('marks-rank-admissions')

[Link]()

# histogram
import [Link] as plt
emp_ages = [22,45,30,60,60,56,60,45,43,43,50,40,34,33,25,19]
bins = [0,10,20,30,40,50,60,70]

# histtype= {‘bar’, ‘barstacked’, ‘step’, ‘stepfilled’}


[Link](emp_ages, bins, histtype='bar', rwidth=0.8, color='cyan')

[Link]('employee ages')
[Link]('No. of employees')
[Link]('MICROSOFT INC.')

[Link]()

You might also like