summaryrefslogtreecommitdiff
path: root/examples/plotUpdateImageFromThread.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/plotUpdateImageFromThread.py')
-rw-r--r--examples/plotUpdateImageFromThread.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/examples/plotUpdateImageFromThread.py b/examples/plotUpdateImageFromThread.py
index 5850263..c594a8a 100644
--- a/examples/plotUpdateImageFromThread.py
+++ b/examples/plotUpdateImageFromThread.py
@@ -1,7 +1,6 @@
-# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2017-2018 European Synchrotron Radiation Facility
+# Copyright (c) 2017-2021 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -72,7 +71,7 @@ class UpdateThread(threading.Thread):
self.running = True
super(UpdateThread, self).start()
- def run(self, pos={'x0': 0, 'y0': 0}):
+ def run(self, pos={"x0": 0, "y0": 0}):
"""Method implementing thread loop that updates the plot
It produces an image every 10 ms or so, and
@@ -89,20 +88,25 @@ class UpdateThread(threading.Thread):
x = numpy.linspace(-1.5, 1.5, Nx)
y = numpy.linspace(-1.0, 1.0, Ny)
xv, yv = numpy.meshgrid(x, y)
- signal = numpy.exp(- ((xv - pos['x0']) ** 2 / sigma_x ** 2
- + (yv - pos['y0']) ** 2 / sigma_y ** 2))
+ signal = numpy.exp(
+ -(
+ (xv - pos["x0"]) ** 2 / sigma_x**2
+ + (yv - pos["y0"]) ** 2 / sigma_y**2
+ )
+ )
# add noise
signal += 0.3 * numpy.random.random(size=signal.shape)
# random walk of center of peak ('drift')
- pos['x0'] += 0.05 * (numpy.random.random() - 0.5)
- pos['y0'] += 0.05 * (numpy.random.random() - 0.5)
+ pos["x0"] += 0.05 * (numpy.random.random() - 0.5)
+ pos["y0"] += 0.05 * (numpy.random.random() - 0.5)
# If previous frame was not added to the plot yet, skip this one
if self.future_result is None or self.future_result.done():
# plot the data asynchronously, and
# keep a reference to the `future` object
self.future_result = concurrent.submitToQtMainThread(
- self.plot2d.addImage, signal, resetzoom=False)
+ self.plot2d.addImage, signal, resetzoom=False
+ )
def stop(self):
"""Stop the update thread"""
@@ -116,18 +120,19 @@ def main():
# Create a Plot2D, set its limits and display it
plot2d = Plot2D()
+ plot2d.getIntensityHistogramAction().setVisible(True)
plot2d.setLimits(0, Nx, 0, Ny)
- plot2d.getDefaultColormap().setVRange(0., 1.5)
+ plot2d.getDefaultColormap().setVRange(0.0, 1.5)
plot2d.show()
# Create the thread that calls submitToQtMainThread
updateThread = UpdateThread(plot2d)
updateThread.start() # Start updating the plot
- app.exec_()
+ app.exec()
updateThread.stop() # Stop updating the plot
-if __name__ == '__main__':
+if __name__ == "__main__":
main()