Practical Graph
Practical Graph
import matplotlib.pyplot as pp
mon =['January','February','March','April','May']
sales = [510,350,475,580,600]
pp.plot(mon, sales, label='Sales', color='b', linestyle='dashed', marker='D')
pp.title("The Monthly Sales Report")
pp.xlabel("Months")
pp.ylabel("Sales")
pp.legend()
pp.show()
Ouptut:
[2] Pratyush Garments has recorded the following data into their register for their income from cotton clothes and jeans.
Plot them on the line chart.
import matplotlib.pyplot as pp
day =['Monday','Tuesday','Wednesday','Thursday','Friday']
ct = [450,560,400,605,580]
js = [490,600,425,610,625]
pp.plot(day,ct,label='Cotton',color='g',linestyle='dotted',marker='+')
pp.plot(day,js,label='Food',color='m',linestyle='dashdot',marker='x')
pp.title("The Weekly Garment Orders")
pp.xlabel("Days")
pp.ylabel("Orders")
pp.legend()
pp.show()
Output:
[3]. Write a program to plot a range from 1 to 30 with step value 4. Use following algebraic expression to show data.
y = 5*x+2
import matplotlib.pyplot as pp
import numpy as np
x = np.arange(1,30,4)
y=5*x+2
pp.plot(x,y)
pp.show()
[4] Display following bowling figures through bar chart:
Overs Runs
1 6
2 18
3 10
4 5
Import matplotlib.pyplot as pp
overs =[1,2,3,4]
runs=[6,18,10,5]
pp.bar(overs,runs,color='m')
pp.xlabel('Overs')
pp.xlabel('Runs')
pp.title('Bowling Spell Analysis')
pp.show()
[5] Execute the following codes and find out what happens? (Libraries have been imported
already; plt is the alias name formatplotlib.pyplot)
(a)
A = np.arange(2, 20, 2)
B = np.log(A)
plt.plot(A, B)
plt.show()
(b)
A = np.arange(2, 20, 2)
B= np.log(A)
plt.bar(A, B)
plt.show()
(c)
X = np.arange(1, 18, 2.655)
B = np.log(X)
plt.scatter(X, Y)
plt.show()
#method 1 setting bin edges manually and setting the xticks to bin edges
b1=[3,5.5,7.5,10]
plt.hist(data, bins=b1)
plt.xticks(b1)
plt.grid()
plt.show()