improve ultrasound plot clients
- make plot window not to raise to the front on replot - chmod +x
This commit is contained in:
@ -6,10 +6,40 @@ Created on Tue Feb 4 11:07:56 2020
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
# disable the behaviour of raising the window to the front each time it is updated
|
||||
plt.rcParams["figure.raise_window"] = False
|
||||
|
||||
|
||||
NAN = float('nan')
|
||||
|
||||
|
||||
class Pause:
|
||||
"""allows to leave the plot loop when the window is closed
|
||||
|
||||
Usage:
|
||||
pause = Pause(fig)
|
||||
|
||||
# do initial plots
|
||||
plt.show()
|
||||
while pause(0.5):
|
||||
# do plot updates
|
||||
plt.draw()
|
||||
"""
|
||||
def __init__(self, fig):
|
||||
fig.canvas.mpl_connect('close_event', self.on_close)
|
||||
self.running = True
|
||||
|
||||
def on_close(self, event):
|
||||
self.running = False
|
||||
|
||||
def __call__(self, interval):
|
||||
try:
|
||||
plt.pause(interval)
|
||||
except Exception:
|
||||
pass
|
||||
return self.running
|
||||
|
||||
|
||||
def rect(x1, x2, y1, y2):
|
||||
return np.array([[x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1]])
|
||||
|
||||
@ -29,6 +59,10 @@ class Plot:
|
||||
self.first = True
|
||||
self.fig = None
|
||||
|
||||
def pause(self, interval):
|
||||
"""will be overridden when figure is created"""
|
||||
return False
|
||||
|
||||
def set_line(self, iax, name, data, fmt, **kwds):
|
||||
"""
|
||||
plot or update a line
|
||||
@ -57,9 +91,6 @@ class Plot:
|
||||
self.fig = None
|
||||
self.first = True
|
||||
|
||||
def on_close(self, event):
|
||||
self.fig = None
|
||||
|
||||
def plot(self, curves, rois=None, average=None):
|
||||
boxes = rects(rois[1:], self.yaxis[0])
|
||||
pbox = rect(*rois[0], *self.yaxis[1])
|
||||
@ -74,7 +105,7 @@ class Plot:
|
||||
if self.first:
|
||||
plt.ion()
|
||||
self.fig, axleft = plt.subplots(figsize=(15,7))
|
||||
self.fig.canvas.mpl_connect('close_event', self.on_close)
|
||||
self.pause = Pause(self.fig)
|
||||
plt.title("I/Q", fontsize=14)
|
||||
axleft.set_xlim(0, curves[0][-1])
|
||||
self.ax = [axleft, axleft.twinx()]
|
||||
@ -104,5 +135,6 @@ class Plot:
|
||||
self.first = False
|
||||
|
||||
plt.draw()
|
||||
# TODO: do not know why this is needed:
|
||||
self.fig.canvas.draw()
|
||||
self.fig.canvas.flush_events()
|
||||
|
Reference in New Issue
Block a user