summaryrefslogtreecommitdiff
path: root/examples/plotStats.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/plotStats.py')
-rw-r--r--examples/plotStats.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/examples/plotStats.py b/examples/plotStats.py
index 030caf8..dd6e4f8 100644
--- a/examples/plotStats.py
+++ b/examples/plotStats.py
@@ -1,8 +1,7 @@
#!/usr/bin/env python
-# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2019 European Synchrotron Radiation Facility
+# Copyright (c) 2016-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
@@ -78,7 +77,7 @@ class UpdateThread(threading.Thread):
numpy.arange(1000),
numpy.random.random(1000),
resetzoom=False,
- legend=random.choice(('mycurve0', 'mycurve1'))
+ legend=random.choice(("mycurve0", "mycurve1")),
)
def stop(self):
@@ -91,8 +90,9 @@ class Integral(StatBase):
"""
Simple calculation of the line integral
"""
+
def __init__(self):
- StatBase.__init__(self, name='integral', compatibleKinds=('curve',))
+ StatBase.__init__(self, name="integral", compatibleKinds=("curve",))
def calculate(self, context):
xData, yData = context.data
@@ -103,23 +103,24 @@ class COM(StatBase):
"""
Compute data center of mass
"""
+
def __init__(self):
- StatBase.__init__(self, name='COM', description="Center of mass")
+ StatBase.__init__(self, name="COM", description="Center of mass")
def calculate(self, context):
- if context.kind in ('curve', 'histogram'):
+ if context.kind in ("curve", "histogram"):
xData, yData = context.data
deno = numpy.sum(yData).astype(numpy.float32)
if deno == 0.0:
return 0.0
else:
return numpy.sum(xData * yData).astype(numpy.float32) / deno
- elif context.kind == 'scatter':
+ elif context.kind == "scatter":
xData, yData, values = context.data
values = values.astype(numpy.float64)
deno = numpy.sum(values)
if deno == 0.0:
- return float('inf'), float('inf')
+ return float("inf"), float("inf")
else:
comX = numpy.sum(xData * values) / deno
comY = numpy.sum(yData * values) / deno
@@ -129,9 +130,8 @@ class COM(StatBase):
def main(argv):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
- '--update-mode',
- default='auto',
- help='update mode to display (manual or auto)')
+ "--update-mode", default="auto", help="update mode to display (manual or auto)"
+ )
options = parser.parse_args(argv[1:])
@@ -143,16 +143,18 @@ def main(argv):
updateThread = UpdateThread(plot)
updateThread.start() # Start updating the plot
- plot.addScatter(x=[0, 2, 5, 5, 12, 20],
- y=[2, 3, 4, 20, 15, 6],
- value=[5, 6, 7, 10, 90, 20],
- colormap=Colormap('viridis'),
- legend='myScatter')
+ plot.addScatter(
+ x=[0, 2, 5, 5, 12, 20],
+ y=[2, 3, 4, 20, 15, 6],
+ value=[5, 6, 7, 10, 90, 20],
+ colormap=Colormap("viridis"),
+ legend="myScatter",
+ )
stats = [
- ('sum', numpy.sum),
+ ("sum", numpy.sum),
Integral(),
- (COM(), '{0:.2f}'),
+ (COM(), "{0:.2f}"),
]
plot.getStatsWidget().setStats(stats)
@@ -161,10 +163,11 @@ def main(argv):
plot.getStatsWidget().parent().setVisible(True)
plot.show()
- app.exec_()
+ app.exec()
updateThread.stop() # Stop updating the plot
-if __name__ == '__main__':
+if __name__ == "__main__":
import sys
+
main(sys.argv)