From c2533934a83083e980bff688f063468a9cb15c8d Mon Sep 17 00:00:00 2001
From: Ed Rogers <etr@orc.soton.ac.uk>
Date: Sat, 31 Mar 2018 13:52:10 +0200
Subject: [PATCH] Add update of bar

---
 HearingTest.py | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/HearingTest.py b/HearingTest.py
index 3e9b7a9..fe32f39 100644
--- a/HearingTest.py
+++ b/HearingTest.py
@@ -68,26 +68,37 @@ class HearingMplCanvas(FigureCanvas):
                                    QtWidgets.QSizePolicy.Expanding,
                                    QtWidgets.QSizePolicy.Expanding)
         FigureCanvas.updateGeometry(self)
+        self.ul_bar = None
+        self.ll_bar = None
         self.plot_result(HearingResult(parent.library.freqs))
 
     def plot_result(self, result: HearingResult):
         inds = np.arange(0, result.bands.size)
         baseline = -10
         self.axes.set_axis_bgcolor('k')
-        self.axes.bar(inds, result.upper_bounds-baseline, color=(0, 0.5, 0), bottom=baseline)
-        self.axes.bar(inds, result.lower_bounds-baseline, color=(0, 1, 0), bottom=baseline)
+        self.ul_bar = self.axes.bar(inds, result.upper_bounds-baseline, color=(0, 0.5, 0), bottom=baseline)
+        self.ll_bar = self.axes.bar(inds, result.lower_bounds-baseline, color=(0, 1, 0), bottom=baseline)
         xlim = self.axes.get_xlim()
         for i in np.arange(result.lower_lim+baseline, result.upper_lim, result.get_block_size()):
             self.axes.plot(self.axes.get_xlim(), np.ones(2)*i, color='k')
         labels = [str(b) for b in result.bands]
         labels.insert(0, '')
         self.axes.set_xticklabels(labels)
-        print(result.bands)
-        print(labels)
-        print(result.lower_bounds)
+        # print(result.bands)
+        # print(labels)
+        # print(result.lower_bounds)
         self.axes.set_ylim(-10, 110)
         self.axes.set_xlim(xlim)
 
+    def update_result(self, result: HearingResult) -> None:
+        self.set_bar_heights(self.ul_bar, result.upper_bounds)
+        self.set_bar_heights(self.ll_bar, result.lower_bounds)
+
+    @staticmethod
+    def set_bar_heights(bars: matplotlib.container.BarContainer, vals: np.ndarray):
+        for bar, h in zip(bars, vals):
+            bar.set_height(h)
+
 
 class HearingTestThread(QtCore.QThread):
     played_sound = QtCore.pyqtSignal(float, float)
@@ -152,7 +163,7 @@ class TestWindow(QMainWindow):
         self.log.setText('')
         self.title.setText('Test running')
         self.log.append('Starting...')
-        self.testing_thread = HearingTestThread(self.library)
+        self.testing_thread = HearingTestThread(self.library, result)
         self.testing_thread.played_sound.connect(self.sound_played)
         self.testing_thread.finished.connect(self.test_finished)
         self.testing_thread.start()
-- 
GitLab