-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotWindow.py
More file actions
93 lines (55 loc) · 2.23 KB
/
PlotWindow.py
File metadata and controls
93 lines (55 loc) · 2.23 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 1 14:01:38 2018
@author: anwaldt
"""
import sys
import random
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QMainWindow, QAction, QFileDialog, QDialog)
from PyQt5.QtWidgets import (QApplication, QGridLayout, QGroupBox,QDialog, QSlider,
QMenu, QPushButton, QRadioButton, QVBoxLayout,QHBoxLayout, QWidget, QButtonGroup, QAbstractButton, QLabel)
from PyQt5.QtGui import (QIcon)
from OscPlayer import OscPlayer
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
class PlotWindow(QDialog):
def __init__(self, parent=None):
super(PlotWindow, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QPushButton('Plot')
self.button.clicked.connect(self.plot)
# set the layout
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
def set_data(self, player):
self.player = player
print(player.mainPath)
self.setWindowTitle(player.mainPath)
self.plot()
def plot(self):
''' plot some random stuff '''
# random data
data = self.player.values
# instead of ax.hold(False)
self.figure.clear()
# create an axis
ax = self.figure.add_subplot(111)
# plot data
ax.plot(self.player.t, data)
ax.set_xlabel('t / s')
# refresh canvas
self.canvas.draw()