forked from Strong10mede/Module-Based_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatplotlib Based
More file actions
109 lines (86 loc) · 2.22 KB
/
Matplotlib Based
File metadata and controls
109 lines (86 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import matplotlib.pyplot as plt //i am raghav sethi
from matplotlib import style
#normal
plt.plot([1,2,3],[4,3,5])
plt.show()
#normal2
x=[5,8,11]
y=[6,8,5]
plt.title("Graph")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.plot(x,y)
plt.show()
#usingstyle
style.use('ggplot')
x1=[2,4,6]
y1=[6,2,3]
plt.plot(x,y,'g',label='One Time',linewidth=5)
plt.plot(x1,y1,'c',label='Two Time',linewidth=5)
plt.title("Graph")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.grid(True,color='k')
plt.legend()
plt.show()
#bar
plt.bar([1,2,3,4,5],[5,6,3,8,7],label='Once',width=0.5)
plt.bar([1.5,2.5,3.5,4.5,5.5],[5,7,3,8,9],color='g',label='Twice',width=0.5)
plt.title("Graph")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.legend()
plt.show()
#histogram
population_ages=[11,5,31,49,56,75,13,8,76,34,45,34,52]
bins=[0,10,20,30,40,50,60,70,80]
plt.hist(population_ages,bins,histtype='bar',rwidth=0.5)
plt.title("Graph")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.show()
#scatter
x2=[1,2,3,4,5,6,7,8]
y2=[6,3,4,5,6,7,2,4]
plt.scatter(x2,y2,label='Skitscat',color='k')
plt.title("Graph")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.legend()
plt.show()
#stack plot
days=[1,2,3,4,5]
sleeping=[7,8,6,11,7]
eating=[2,3,2,3,4]
working=[5,6,4,6,6]
playing=[1,2,2,1,0.1]
entertaining=[4,3,4,4,5]
plt.plot([],[],label='sleeping',color='m',linewidth=5)
plt.plot([],[],label='eating',color='c',linewidth=5)
plt.plot([],[],label='working',color='k',linewidth=5)
plt.plot([],[],label='playing',color='r',linewidth=5)
plt.plot([],[],label='entertaining',color='g',linewidth=5)
plt.stackplot(days,sleeping,eating,working,playing,entertaining,colors=['m','c','k','r','g'])
plt.title("Graph")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.legend()
plt.show()
#piechart
slices=[7,3,4,5,12]
activites=['sleeping','eating','working','playing','entertaining']
col=['m','c','b','r','g']
plt.pie(slices,rotatelabels=activites,colors=col,startangle=90,explode=(0,0.1,0,0,0.2),shadow=True,autopct='%1.1f%%')
plt.title('Pie Chart')
plt.show()
#multipleplots
import numpy as np
def f(t):
return np.exp(-t)*np.cos(2*np.pi*t)
t1=np.arange(0.0,5.0,0.1)
t2=np.arange(0.0,5.0,0.02)
plt.subplot(211)
plt.plot(t1,f(t1),'o',t2,f(t2))
plt.subplot(212)
plt.plot(t2,np.cos(2*np.pi*t2))
plt.show()