PYPLOT ASSIGNMENT
1. #To plot list elements using Line Chart
#in Python pyplot
import matplotlib.pyplot as plt
list2 = [1, 2, 3, 4, 5, 6, 7 ]
plt.plot(list2)
plt.ylabel('some numbers')
plt.show()
2. a=[20,30,40,50]
b=[2,4,6,8]
plt.plot(a,b)
plt.show()
3.#Program to plot frequency of marks using Line Chart
def fnplot(list1):
plt.plot(list1)
plt.title("Marks Line Chart")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
list1=[50,50,50,65,65,75,75,80,80,90,90,90,90]
fnplot(list)
4.plt.plot([1,2,3,4],[1,4,9,16])
plt.show()
5. plt.plot([1,2,8,4],[1,4,9,16])
plt.title("First Plot")
plt.xlabel(" X Label")
plt.ylabel("Y Label")
plt.show()
6.
plt.figure(figsize=(4,4))
plt.plot([1,2,3,4],[1,4,9,16])
plt.title("First Plot")
plt.xlabel(" X Label")
plt.ylabel("Y Label")
plt.show()
7. city=['del','mum','chandig','bang']
popu=[23456,5000,1876,1234]
plt.bar(city,popu)
plt.show()
8.#Write a code to generate the histogram of Result to display No of students and their marks.
9.#A survey gathers heights and weight of 50 participates and recorded the participants age as
Ages=[40,56,46,58,79,70,67,46,32,91,92,93,47,95,69,69,56,50,30,9,29,29,0,31,21,14,18,1 6,18,76,68,69,78,81,71,91,71,01,69,78,77,54,59,59,41,51,48,49,76,10]
#Generate the histogram of the above data.
10.#Write a Python code to display a histogram for students data and save the graph in student.png
11.#Write a code to display line chart of IPL Score (Over & Score)
12.#Write a code to plot bar chart Olympics Top scores
import matplotlib.pyplot as p1
import numpy as np
countries=['CANADA','INDIA','SRILANKA','RUSSIA','GERMANY']
bronzes = np.array([40, 20, 25, 15, 5])
silvers = np.array([35, 27, 21, 18, 7])
golds = np.array([45, 22, 36, 15, 19])
ind = np.arange(len(countries))
p1.bar(ind, bronzes, width=0.8, label='bronzes', color='#CD853F')
p1.bar(ind, silvers, width=0.8, label='silvers', color='silver', bottom=bronzes)
p1.bar(ind, golds, width=0.8, label='golds', color='gold', bottom=silvers+bronzes)
p1.xticks(ind, countries)
p1.ylabel("Medals")
p1.xlabel("Countries")
p1.legend(loc="upper right")
p1.title("2012 Olympics Top Scorers")
p1.grid()
p1.show()
13.#Population comparison between India and Pakistan
from matplotlib import pyplot as plt
year = [1960, 1970, 1980, 1990, 2000, 2010]
popul_pakistan = [44.91, 58.09, 78.07, 107.7, 138.5, 170.6]
popul_india = [449.48, 553.57, 696.783, 870.133, 1000.4, 1309.1]
plt.plot(year, popul_pakistan, color='green')
plt.plot(year, popul_india, color='orange')
plt.xlabel('Countries')
plt.ylabel('Population in million')
plt.title('India v/s Pakistan Population till 2010')
plt.show()
14.#Program to exhibit different line styles
import matplotlib.pyplot as plt
import numpy as np
y = np.arange(1, 3)
plt.plot(y, '--', y+1, '-.', y+2, ':')
plt.show()
15. #Program to plot a Bar chart on the basis of popularity
#of Programming Languages
import numpy as np
import matplotlib.pyplot as plt
objects = ('DotNet', 'C++', 'Java', 'Python', 'C', 'CGI/PERL')
y_pos = np.arange(len(objects))
performance = [8,10,9,20,4,1]
plt.bar(y_pos, performance, align='center')
plt.xticks(y_pos, objects,rotation=30) #set location and label
plt.ylabel('Usage')
plt.title('Programming language usage')
plt.show()
DATAFRAME
16.#Predict the output of the following code:
import pandas as pd
d1 = {'rollno': [101,101,103,102,104], 'name': ['Pat', 'Sid', 'Tom', 'Kim', 'Ray'],
'physics': [90,40,50,90,65], 'chem': [75,80,60,85,60]}
df = pd.DataFrame(d1)
print (df)
print(' ------- Basic aggregate functions min (), max (), sum () and mean()')
print('minimum is:', df['physics'].min())
print('maximum is:',df['physics'].max())
print('sum is:',df['physics'].sum ())
print('average is:',df['physics'].mean())
Comments
Post a Comment