Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45add05

Browse files
committed
MEP12 on system_monitor.py
1 parent 0a5314a commit 45add05

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
#!/usr/bin/env python
22
# -*- noplot -*-
33
import time
4-
from pylab import *
5-
4+
import matplotlib.pyplot as plt
5+
import numpy as np
66

77
def get_memory():
88
"Simulate a function that returns system memory"
9-
return 100*(0.5 + 0.5*sin(0.5*pi*time.time()))
10-
9+
return 100*(0.5 + 0.5*np.sin(0.5*np.pi*time.time()))
1110

1211
def get_cpu():
1312
"Simulate a function that returns cpu usage"
14-
return 100*(0.5 + 0.5*sin(0.2*pi*(time.time() - 0.25)))
15-
13+
return 100*(0.5 + 0.5*np.sin(0.2*np.pi*(time.time() - 0.25)))
1614

1715
def get_net():
1816
"Simulate a function that returns network bandwidth"
19-
return 100*(0.5 + 0.5*sin(0.7*pi*(time.time() - 0.1)))
20-
17+
return 100*(0.5 + 0.5*np.sin(0.7*np.pi*(time.time() - 0.1)))
2118

2219
def get_stats():
2320
return get_memory(), get_cpu(), get_net()
2421

2522
# turn interactive mode on for dynamic updates. If you aren't in
2623
# interactive mode, you'll need to use a GUI event handler/timer.
27-
ion()
24+
plt.ion()
2825

2926
fig, ax = plt.subplots()
30-
ind = arange(1, 4)
31-
pm, pc, pn = bar(ind, get_stats())
27+
ind = np.arange(1, 4)
28+
pm, pc, pn = plt.bar(ind, get_stats())
3229
centers = ind + 0.5*pm.get_width()
3330
pm.set_facecolor('r')
3431
pc.set_facecolor('g')
@@ -48,4 +45,4 @@ def get_stats():
4845
pn.set_height(n)
4946
ax.set_ylim([0, 100])
5047

51-
draw()
48+
plt.draw()

0 commit comments

Comments
 (0)