Skip to main content

REVISION - GRADE XII - MATPLOTLIB

 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

Popular posts from this blog

CS - SORTING/SEARCHING ALGORITHMS

  SORTING ALGORITHMS                       SORTING ALGORITHM PDF LINK #Bubble Sort          ·        The outer loop iterates through the entire array. ·        The inner loop compares adjacent elements and swaps them if they are out of order. ·        The outer loop runs n times, and each pass moves the largest element to its correct position. arr=[3,8,5,2,1] n = len(arr) print(n) for i in range(n):  #traverse through all the elements         # Last i elements are already sorted, no need to check them         for j in range(0, n-i-1):              # Swap if the element found is greater than the next element              if arr[j] > arr[j+1]:               ...

GRADE XI - NESTED FOR LOOP

                                                         NESTED FOR LOOP 1. for var1 in range(3):      print(var1,"OUTER LOOP")          # 0 outer loop       1 outer loop      2 outer loop          for var2 in range(2):                  print(var2+1,"INNER LOOP")    #1  2 inner loop     1  2  inner loop   1 2 inner loop  2. Print the following pattern using for loop: 1  1 2  1 2 3  1 2 3 4  Sol: for r in range(1,5):   #ROWS     for c in range(1,r+1):   #COLUMNS         print(c,end=" ")     print() 3. Print the following pattern using for loop: @  @ @  @ @ @...