Skip to content

Commit 2e1c261

Browse files
Matplot initial commit
1 parent f4289dc commit 2e1c261

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

Matplot/Liveplot.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import matplotlib.pyplot as plt
2+
import matplotlib.animation as animation
3+
from matplotlib import style
4+
import os
5+
6+
scriptDir = os.path.dirname(os.path.realpath(__file__))
7+
8+
style.use('fivethirtyeight')
9+
10+
figure = plt.figure()
11+
axis1 = figure.add_subplot(1,1,1)
12+
13+
14+
def animate(i):
15+
graph_data = open(scriptDir + os.path.sep + 'example.txt','r').read()
16+
lines = graph_data.split('\n')
17+
xs = []
18+
ys = []
19+
for line in lines:
20+
if len(line) > 1:
21+
x , y = line.split(',')
22+
xs.append(x)
23+
ys.append(y)
24+
25+
axis1.clear()
26+
axis1.plot(xs,ys)
27+
28+
29+
30+
if __name__ =='__main__':
31+
ani = animation.FuncAnimation(figure,animate,interval=2000)
32+
plt.show()
33+

Matplot/Liveplot1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
plt.axis([0, 10, 0, 1])
5+
6+
for i in range(10):
7+
y = np.random.random()
8+
plt.scatter(i, y)
9+
plt.pause(0.05)
10+
11+
plt.show()

Matplot/Liveplot2.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
from random import randint
4+
5+
6+
# x and x1 , y and y1
7+
plt.axis([0,10,0,10])
8+
9+
10+
x=list()
11+
y=list()
12+
13+
for i in range(10):
14+
temp_y= randint(0,10)
15+
x.append(i);
16+
y.append(temp_y);
17+
plt.scatter(i,temp_y);
18+
plt.pause(0.2) #Note this correction
19+
20+
21+
22+
plt.show()

Matplot/example.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
1,5
2+
2,3
3+
3,4
4+
4,7
5+
5,4
6+
6,3
7+
7,5
8+
8,7
9+
9,4
10+
10,4
11+
11,5
12+
12,15
13+
13,7
14+
14,5
15+
15,4
16+
16,5
17+

0 commit comments

Comments
 (0)