-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
97 lines (77 loc) · 2.68 KB
/
plot.py
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
96
97
import random
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QSizePolicy, QPushButton, QMainWindow, QWidget
class Canvas(FigureCanvas):
def __init__(self, parent=None):
fig = Figure()
self.axes = fig.add_subplot(111)
self.axes2 = fig.add_subplot(111)
super(Canvas, self).__init__(fig)
self.setParent(parent)
timer = QTimer(self)
timer.timeout.connect(self.update_figure)
timer.start(500)
self.x = tbx
self.y = tby
self.setWindowTitle(sys.argv[1])
def update_figure(self):
self.axes.clear()
self.axes.plot(self.x, self.y, 'bo')
if hasattr(self, 'x2'):
self.axes2.plot(self.x2, self.y2, 'ro')
self.draw()
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.form_widget = FormWidget(self)
self.setCentralWidget(self.form_widget)
class FormWidget(QWidget):
def __init__(self, parent):
super(FormWidget, self).__init__(parent)
self.layout = QVBoxLayout(self)
self.canvas = Canvas()
self.layout.addWidget(self.canvas)
self.blm_btn = QPushButton("Black Lives Matter")
self.blm_btn.clicked.connect(self.blmGraph)
self.layout.addWidget(self.blm_btn)
self.maga_btn = QPushButton("Make America Great Again")
self.maga_btn.clicked.connect(self.magaGraph)
self.layout.addWidget(self.maga_btn)
self.setLayout(self.layout)
self.blmon = True
self.magaon = False
def blmGraph(self):
if self.blmon:
self.blmon = False
self.canvas.x = []
self.canvas.y = []
else:
self.blmon = True
self.canvas.x = tbx
self.canvas.y = tby
def magaGraph(self):
if self.magaon:
self.magaon = False
self.canvas.x2 = []
self.canvas.y2 = []
else:
self.magaon = True
self.canvas.x2 = tbx2
self.canvas.y2 = tby2
if __name__ == '__main__':
import sys
f = open(str(sys.argv[1]) + "_results")
tb = [eval(x) for x in f.read().split("\n")]
tbx = [x[0] for x in tb]
tby = [x[1] for x in tb]
f = open(str(sys.argv[2]) + "_results")
tb = [eval(x) for x in f.read().split("\n")]
tbx2 = [x[0] for x in tb]
tby2 = [x[1] for x in tb]
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())