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

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...

GRADE XI | DESIGN THINKING & INNOVATION (848) | INTRO | CH-1

  DESIGN THINKING &  INNOVATION (848)  INTRODUCTION LINK : INTRODUCTION PPT PPT LINK Notes: Design Thinking and Innovation Grade XI Introduction Section   I. What is Design? (0.1.1) Definitions from Experts: John Maeda: "Design is solution to a problem". Saul Bass: "Design is thinking made visual". Charles Eames:   “Design is a plan for arranging elements in such a way as best to accomplish a particular purpose.” Steve Jobs:  "Design is not just what it looks like and feels like. Design is how it works". Prof. Sudhakar Nadkarni:  "Essentials of design are— purity, precision, details". Design is a way of understanding needs, identifying problems, and creating appropriate and innovative solutions. It is not only about appearance, but also about usefulness and sustainability. Design is explained as something that helps solve problems and make a positive difference. Key ...