8000 Merge pull request #4648 from ericmjl/mep12-system_monitor.py · matplotlib/matplotlib@8d8ec21 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d8ec21

Browse files
committed
Merge pull request #4648 from ericmjl/mep12-system_monitor.py
MEP12 on system_monitor.py
2 parents 49bb240 + ff81c9c commit 8d8ec21

File tree

1 file changed

+10
-10
lines changed
Collapse file tree

1 file changed

+10
-10
lines changed

examples/pylab_examples/system_monitor.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
#!/usr/bin/env python
2-
# -*- noplot -*-
31
import time
4-
from pylab import *
2+
import matplotlib.pyplot as plt
3+
import numpy as np
54

65

76
def get_memory():
87
"Simulate a function that returns system memory"
9-
return 100*(0.5 + 0.5*sin(0.5*pi*time.time()))
8+
return 100*(0.5 + 0.5*np.sin(0.5*np.pi*time.time()))
109

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)))
13+
return 100*(0.5 + 0.5*np.sin(0.2*np.pi*(time.time() - 0.25)))
1514

1615

1716
def get_net():
1817
"Simulate a function that returns network bandwidth"
19-
return 100*(0.5 + 0.5*sin(0.7*pi*(time.time() - 0.1)))
18+
return 100*(0.5 + 0.5*np.sin(0.7*np.pi*(time.time() - 0.1)))
2019

2120

2221
def get_stats():
2322
return get_memory(), get_cpu(), get_net()
2423

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

2929
fig, ax = plt.subplots()
30-
ind = arange(1, 4)
31-
pm, pc, pn = bar(ind, get_stats())
30+
ind = np.arange(1, 4)
31+
pm, pc, pn = plt.bar(ind, get_stats())
3232
centers = ind + 0.5*pm.get_width()
3333
pm.set_facecolor('r')
3434
pc.set_facecolor('g')
@@ -48,4 +48,4 @@ def get_stats():
4848
pn.set_height(n)
4949
ax.set_ylim([0, 100])
5050

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

0 commit comments

Comments
 (0)
0