0% found this document useful (0 votes)
15 views5 pages

Matplot Lib Programs New

The document contains multiple Python programs that utilize the Matplotlib library to create various types of charts and graphs, including bar charts and line graphs. Each program demonstrates different functionalities such as customizing colors, labels, and legends for visual representation of data. The examples cover plotting logarithmic values, student marks, and mathematical equations.

Uploaded by

NEEMA GANDHI
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)
15 views5 pages

Matplot Lib Programs New

The document contains multiple Python programs that utilize the Matplotlib library to create various types of charts and graphs, including bar charts and line graphs. Each program demonstrates different functionalities such as customizing colors, labels, and legends for visual representation of data. The examples cover plotting logarithmic values, student marks, and mathematical equations.

Uploaded by

NEEMA GANDHI
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
You are on page 1/ 5

#program 1

#bar chart
import matplotlib.pyplot as p
import numpy as n
a=range(1,11)
b=n.log(a)
p.xlim(-4,12)
p.bar(a,b)
p.xlabel("Values")
p.ylabel("Logrithm values")
p.show()
OUTPUT:

#PROGRAM 2
import matplotlib.pyplot as p
names=['Abhi','Ami','Ritu','Ramit']
marks=[225,245,250,234]
p.bar(names,marks)
p.xlabel("Student's Names")
p.ylabel("Total Marks")
p.show()
OUTPUT:

#Program 3
import matplotlib.pyplot as p
names=['Abhi','Ami','Ritu','Ramit']
marks=[225,245,250,234]
p.ylim(150,350)
p.bar(names,marks,color=['r','b','g','y'],width=[1,0.5,0.7,0.25])
p.xlabel("Student's Names")
p.ylabel("Total Marks")
p.legend()
p.show()
Output:

Program 4
import matplotlib.pyplot as p
import numpy as n
info=['Gold','Silver','Bronze']
India=[22,20,30]
Australia=[45,35,40]
England=[26,27,34]
Canada=[34,45,46]
x=n.arange(len(info))
p.bar(info,India,width=.15,label='India')
p.bar(x+.15,Australia,width=.15,label='Australia')
p.bar(x+.30,England,width=.15,label='England')
p.bar(x+.45,Canada,width=.15,label='Canada')
p.xlabel("Medal type")
p.ylabel("Medal Count")
p.legend()
p.show()
OUTPUT:
#program 5
# importing required modules
import matplotlib.pyplot as plt
# values of x and y axes
x = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
y = [1, 4, 3, 2, 7, 6, 9, 8, 10, 5]
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('y')
plt.show()

output:

#Program 6
# importing libraries
import matplotlib.pyplot as plt
import numpy as np
# values of x and y axes
x = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
y = [1, 4, 3, 2, 7, 6, 9, 8, 10, 5]
plt.plot(x, y, 'b')
plt.xlabel('x')
plt.ylabel('y')
# 0 is the initial value, 51 is the final value
# (last value is not taken) and 5 is the difference
# of values between two consecutive ticks
plt.xticks(np.arange(0, 51, 5))
plt.yticks(np.arange(0, 11, 1))
plt.show()
output:
Program – 7
# to draw a line graph for y=4x+3
import numpy as np
import matplotlib.pyplot as mp
x=np.arange(0,10,2)
y=4*x+3
mp.plot(x,y,color='r',linestyle="dashed")
mp.xlabel("X-axis")
mp.ylabel("Y-axis")
mp.title("Equation : y= 4x+3")
mp.show()

Program 8
import numpy as np
import matplotlib.pyplot as mp
a=np.arange(1,20,2)
b=a*10+2
c=np.log(a)
mp.xlabel("number")
mp.ylabel("Value")
mp.title("Graph or Chart")
mp.plot(a,b)
mp.plot(a,c)
mp.show()
output:

Program 9
import matplotlib.pyplot as m

x=['Ruhi','Rani','Ramit','Abhi']
y=[34,45,44,34]
m.plot(x,y,'c',linestyle='dashed', marker='d',markersize=5, markeredgecolor='red')
m.xlabel("Student's Name")
m.ylabel("Marks")
m.show()

You might also like