Skip to main content

REVISION - GRADE XII - MATPLOTLIB

 PYPLOT ASSIGNMENT 

 #1

import matplotlib.pyplot as plt

a=[20,30,40,50]

b=[2,4,6,8]

plt.plot(a,b)

plt.show()

 

#2

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)

 

#3

plt.plot([1,2,3,4],[1,4,9,16])

plt.show()

 

 #4

plt.plot([1,2,8,4],[1,4,9,16])

plt.title("First Plot")

plt.xlabel(" X Label")

plt.ylabel("Y Label")

plt.show()

 

#5

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()

 

#5

plt.plot([12,23,30,47])

plt.title("Second Plot")

plt.xlabel(" X Label")

plt.ylabel("Y Label")

plt.show()

 

#6

plt.subplot(1,2,1)  #the figure has 1 row, 2 columns, and this plot is the first plot.

plt.plot([1,2,3,4],[1,4,9,16],"go")

plt.title("First Plot")


plt.subplot(1,2,2)

plt.plot([1,2,3,4],[1,4,9,16],"r^")

plt.title("Second Plot")

plt.show()


HISTOGRAM

import numpy as np 

import matplotlib.pyplot as p1

a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])

p1.hist(a, bins = [0,25,50,75,100],facecolor='y',edgecolor="red")

p1.title("histogram of result")

p1.xticks([0,25,50,75,100])

p1.xlabel('marks')

p1.ylabel('no. of students')

p1.show()


data_students=[1,11,21,31,41,51]

plt.hist(data_students,bins=[0,10,20,30,40,50,60],weights=[10,1,0,33,6,8],

         facecolor='y',edgecolor="red")

plt.title("Histogram for Students data")

plt.xlabel('Value')

plt.ylabel('Frequency')

#plt.savefig("student.png")

plt.show()


#EG: HISTOGRAM

import matplotlib.pyplot as plt

data_students=[5,15,25,35,45,55]

plt.hist(data_students,bins=[0,10,20,30,40,50,60],weights=[20,10,45,33,6,8],

         facecolor='y',edgecolor="red")

plt.title("Histogram for Students data")

plt.xlabel('Value')

plt.ylabel('Frequency')

plt.savefig("student.png")

plt.show()

#7

import matplotlib.pyplot as plt

import numpy as np

xpoints = np.array([0, 6])

ypoints = np.array([0, 250])

plt.plot(xpoints, ypoints)

plt.show()

 

#8

city=['del','mum','chandig','bang']

popu=[23456,5000,1876,1234]

plt.bar(city,popu)

plt.show()

'''

#9

import numpy as np

x=np.arange(1,5)

y=x**3

print(x)

print(y)

#plt.plot([1,2,3,4],[1,4,9,16],"go",x,y,'r^')

plt.title("First Plot")

plt.xlabel(" X Label")

plt.ylabel("Y Label")

plt.plot(x,y,'y')

plt.plot(x,y,"r^")

plt.show()

  

#10

plt.subplot(1,2,1)

plt.plot([1,2,3,4],[1,4,9,16],"bo")

plt.title("First Plot")

plt.subplot(1,2,2)

plt.plot([1,2,3,4],[1,8,9,20],"r^")

plt.title("Second Plot")

plt.show()

 

#11.

import matplotlib.pyplot as plt

import numpy as np

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

plt.plot(ypoints, marker = 'o')

#or

plt.plot(ypoints, marker = '*')

plt.show()

 

#12.

import matplotlib.pyplot as plt

import numpy as np

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

plt.plot(ypoints, linestyle = 'dotted')

plt.show()


#13.
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()

#14.Population comparison between India and Pakistan
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()

#15. 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()

#16. 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()

17.
x=[1,2,3,4,5]
y=[6,7,8,9,10]
p1.xlabel("DATA FROM A")
p1.ylabel("DATA FROM B")
p1.title("DATA ALL")
p1.bar(x,y)
p1.savefig("f:\pic1.pdf")
p1.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

Popular posts from this blog

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...

GRADE XII CS - VIVA QUESTIONS

  VIVA QUESTIONS GRADE XII CS Dear All Be thorough with your project and practical files, as the viva can be asked from anywhere. Stay calm, don’t get nervous, and be confident in front of the examiner. 1. Tell me about your project. 2. Which concepts you have used for your project? 3. What do you mean by front end and back end? How they are important in developing any such projects? 4  Mention the modules and built-in functions you have used in your project. 5. Which real world problems are solved by your project? 6. Explain the most important feature of your project. 7. Name a few mutable data types of python. Lists, Sets, and Dictionaries 8. Name a few immutable data types of python. Strings, Tuples, Numeric 9. Name ordered and unordered data type of python. Ordered – String, List, Tuples Unordred – Set, Dictionaries 10. What is the significance of a pass statement in python? pass is no operation python statement. This is used where python requires syntax but logic requires...