summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>2019-12-23 13:45:09 +0100
committerPicca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>2019-12-23 13:45:09 +0100
commit5d647cf9a6159afd2933da594b9c79ad93d3cd9b (patch)
tree2571025a602f68fc8933b01104dc712d41f84034 /examples
parent654a6ac93513c3cc1ef97cacd782ff674c6f4559 (diff)
New upstream version 0.12.0~b0+dfsg
Diffstat (limited to 'examples')
-rw-r--r--examples/compositeline.py80
-rw-r--r--examples/exampleBaseline.py164
-rw-r--r--examples/findContours.py4
-rwxr-xr-xexamples/hdf5widget.py9
-rwxr-xr-xexamples/imageview.py7
-rw-r--r--examples/plotInteractiveImageROI.py9
-rwxr-xr-xexamples/scatterview.py99
-rwxr-xr-xexamples/simplewidget.py64
8 files changed, 416 insertions, 20 deletions
diff --git a/examples/compositeline.py b/examples/compositeline.py
new file mode 100644
index 0000000..892ecf3
--- /dev/null
+++ b/examples/compositeline.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+# coding: utf-8
+# /*##########################################################################
+#
+# Copyright (c) 2016-2019 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
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# ###########################################################################*/
+"""
+Example to show the use of markers to draw head and tail of lines.
+"""
+from __future__ import division
+
+__license__ = "MIT"
+
+import logging
+from silx.gui.plot import Plot1D
+from silx.gui import qt
+import numpy
+
+
+logging.basicConfig()
+logger = logging.getLogger(__name__)
+
+
+def main(argv=None):
+ """Display few lines with markers.
+ """
+ global app # QApplication must be global to avoid seg fault on quit
+ app = qt.QApplication([])
+ sys.excepthook = qt.exceptionHandler
+
+ mainWindow = Plot1D(backend="gl")
+ mainWindow.setAttribute(qt.Qt.WA_DeleteOnClose)
+ plot = mainWindow
+ plot.setDataMargins(0.1, 0.1, 0.1, 0.1)
+
+ plot.addCurve(x=[-10,0,0,-10,-10], y=[90,90,10,10,90], legend="box1", color="gray")
+ plot.addCurve(x=[110,100,100,110,110], y=[90,90,10,10,90], legend="box2", color="gray")
+ plot.addCurve(y=[-10,0,0,-10,-10], x=[90,90,10,10,90], legend="box3", color="gray")
+ plot.addCurve(y=[110,100,100,110,110], x=[90,90,10,10,90], legend="box4", color="gray")
+
+ def addLine(source, destination, symbolSource, symbolDestination, legend, color):
+ line = numpy.array([source, destination]).T
+ plot.addCurve(x=line[0,:], y=line[1,:], color=color, legend=legend)
+ plot.addMarker(x=source[0], y=source[1], symbol=symbolSource, color=color)
+ plot.addMarker(x=destination[0], y=destination[1], symbol=symbolDestination, color=color)
+
+ addLine([0, 50], [100, 50], "caretleft", "caretright", "l1", "red")
+ addLine([0, 30], [100, 30], "tickup", "tickdown", "l2", "blue")
+ addLine([0, 70], [100, 70], "|", "|", "l3", "black")
+
+ addLine([50, 0], [50, 100], "caretdown", "caretup", "l4", "red")
+ addLine([30, 0], [30, 100], "tickleft", "tickright", "l5", "blue")
+ addLine([70, 0], [70, 100], "_", "_", "l6", "black")
+
+ mainWindow.setVisible(True)
+ return app.exec_()
+
+
+if __name__ == "__main__":
+ import sys
+ sys.exit(main(argv=sys.argv[1:]))
diff --git a/examples/exampleBaseline.py b/examples/exampleBaseline.py
new file mode 100644
index 0000000..edd0fc3
--- /dev/null
+++ b/examples/exampleBaseline.py
@@ -0,0 +1,164 @@
+#!/usr/bin/env python
+# coding: utf-8
+# /*##########################################################################
+#
+# Copyright (c) 2017-2018 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
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# ###########################################################################*/
+"""This example illustrates some usage possible with the baseline parameter
+"""
+
+__authors__ = ["H. Payno"]
+__license__ = "MIT"
+__date__ = "12/09/2019"
+
+
+from silx.gui import qt
+from silx.gui.plot import Plot1D
+import numpy
+import sys
+import argparse
+
+
+def stacked_histogran(plot, edges, histograms, colors, legend):
+ # check that we have the same number of histogram, color and baseline
+ current_baseline = numpy.zeros_like(edges)
+
+ for histogram, color, layer_index in zip(histograms, colors, range(len(colors))):
+ stacked_histo = histogram + current_baseline
+ plot.addHistogram(histogram=stacked_histo,
+ edges=edges,
+ legend='_'.join((legend, str(layer_index))),
+ color=color,
+ baseline=current_baseline,
+ z=len(histograms)-layer_index,
+ fill=True)
+ current_baseline = stacked_histo
+
+
+def get_plot_std(backend):
+ x = numpy.arange(0, 10, step=0.1)
+ my_sin = numpy.sin(x)
+ y = numpy.arange(-4, 6, step=0.1) + my_sin
+ mean = numpy.arange(-5, 5, step=0.1) + my_sin
+ baseline = numpy.arange(-6, 4, step=0.1) + my_sin
+ edges = x[y >= 3.0]
+ histo = mean[y >= 3.0] - 1.8
+
+ plot = Plot1D(backend=backend)
+ plot.addCurve(x=x, y=y, baseline=baseline, color='grey',
+ legend='std-curve', fill=True)
+ plot.addCurve(x=x, y=mean, color='red', legend='mean')
+ plot.addHistogram(histogram=histo, edges=edges, color='red',
+ legend='mean2', fill=True)
+ return plot
+
+
+def get_plot_stacked_histogram(backend):
+ plot = Plot1D(backend=backend)
+ # first histogram
+ edges = numpy.arange(-6, 6, step=0.5)
+ histo_1 = numpy.random.random(len(edges))
+ histo_2 = numpy.random.random(len(edges))
+ histo_3 = numpy.random.random(len(edges))
+ histo_4 = numpy.random.random(len(edges))
+ stacked_histogran(plot=plot,
+ edges=edges,
+ histograms=(histo_1, histo_2, histo_3, histo_4),
+ colors=('blue', 'green', 'red', 'yellow'),
+ legend='first_stacked_histo')
+
+ # second histogram
+ edges = numpy.arange(10, 25, step=1.0)
+ histo_1 = -numpy.random.random(len(edges))
+ histo_2 = -numpy.random.random(len(edges))
+ stacked_histogran(plot=plot, histograms=(histo_1, histo_2),
+ edges=edges,
+ colors=('gray', 'black'),
+ legend='second_stacked_histo')
+
+ # last histogram
+ edges = [30, 40]
+ histograms = [
+ [0.2, 0.3],
+ [0.0, 1.0],
+ [0.1, 0.4],
+ [0.2, 0.0],
+ [0.6, 0.4],
+ ]
+ stacked_histogran(plot=plot,
+ histograms=histograms,
+ edges=edges,
+ colors=('blue', 'green', 'red', 'yellow', 'cyan'),
+ legend='third_stacked_histo')
+
+ return plot
+
+
+def get_plot_mean_baseline(backend):
+ plot = Plot1D(backend=backend)
+ x = numpy.arange(0, 10, step=0.1)
+ y = numpy.sin(x)
+ plot.addCurve(x=x, y=y, baseline=0, fill=True)
+ plot.setYAxisLogarithmic(True)
+ return plot
+
+
+def get_plot_log(backend):
+ plot = Plot1D(backend=backend)
+ x = numpy.arange(0, 10, step=0.01)
+ y = numpy.exp2(x)
+ baseline = numpy.exp(x)
+ plot.addCurve(x=x, y=y, baseline=baseline, fill=True)
+ plot.setYAxisLogarithmic(True)
+ return plot
+
+
+def main(argv):
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument(
+ '--backend',
+ dest="backend",
+ action="store",
+ default=None,
+ help='Set plot backend. Should be "matplotlib" (default) or "opengl"')
+
+ options = parser.parse_args(argv[1:])
+ assert options.backend in (None, 'matplotlib', 'opengl')
+ qapp = qt.QApplication([])
+
+ plot_std = get_plot_std(backend=options.backend)
+ plot_std.show()
+
+ plot_mean = get_plot_mean_baseline(backend=options.backend)
+ plot_mean.show()
+
+ plot_stacked_histo = get_plot_stacked_histogram(backend=options.backend)
+ plot_stacked_histo.show()
+
+ plot_log = get_plot_log(backend=options.backend)
+ plot_log.show()
+
+ qapp.exec_()
+
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/examples/findContours.py b/examples/findContours.py
index a5bb663..a7b5ac4 100644
--- a/examples/findContours.py
+++ b/examples/findContours.py
@@ -2,7 +2,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (c) 2016-2019 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
@@ -25,7 +25,7 @@
# ###########################################################################*/
"""Find contours examples
-.. note:: This module has an optional dependancy with sci-kit image library.
+.. note:: This module has an optional dependency with sci-kit image library.
You might need to install it if you don't already have it.
"""
diff --git a/examples/hdf5widget.py b/examples/hdf5widget.py
index c344bec..217eb7f 100755
--- a/examples/hdf5widget.py
+++ b/examples/hdf5widget.py
@@ -2,7 +2,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (c) 2016-2019 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
@@ -23,12 +23,7 @@
# THE SOFTWARE.
#
# ###########################################################################*/
-"""Qt Hdf5 widget examples
-
-.. note:: This module has a dependency on the `h5py <http://www.h5py.org/>`_
- library, which is not a mandatory dependency for `silx`. You might need
- to install it if you don't already have it.
-"""
+"""Qt Hdf5 widget examples"""
import logging
import sys
diff --git a/examples/imageview.py b/examples/imageview.py
index 71bde70..5c7eddb 100755
--- a/examples/imageview.py
+++ b/examples/imageview.py
@@ -2,7 +2,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (c) 2016-2019 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
@@ -32,11 +32,6 @@ To view an image file with the current installed silx library:
``python examples/imageview.py <file to open>``
To get help:
``python examples/imageview.py -h``
-
-For developers with a git clone you can use it with the bootstrap
-To view an image file with the current installed silx library:
-
-``./bootstrap.py python examples/imageview.py <file to open>``
"""
from __future__ import division
diff --git a/examples/plotInteractiveImageROI.py b/examples/plotInteractiveImageROI.py
index e06db89..8a4019f 100644
--- a/examples/plotInteractiveImageROI.py
+++ b/examples/plotInteractiveImageROI.py
@@ -2,7 +2,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2018 European Synchrotron Radiation Facility
+# Copyright (c) 2018-2019 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
@@ -71,13 +71,12 @@ roiManager.setColor('pink') # Set the color of ROI
# Set the name of each created region of interest
def updateAddedRegionOfInterest(roi):
"""Called for each added region of interest: set the name"""
- if roi.getLabel() == '':
- roi.setLabel('ROI %d' % len(roiManager.getRois()))
+ if roi.getName() == '':
+ roi.setName('ROI %d' % len(roiManager.getRois()))
if isinstance(roi, LineMixIn):
roi.setLineWidth(2)
roi.setLineStyle('--')
if isinstance(roi, SymbolMixIn):
- roi.setSymbol('o')
roi.setSymbolSize(5)
@@ -86,7 +85,7 @@ roiManager.sigRoiAdded.connect(updateAddedRegionOfInterest)
# Add a rectangular region of interest
roi = RectangleROI()
roi.setGeometry(origin=(50, 50), size=(200, 200))
-roi.setLabel('Initial ROI')
+roi.setName('Initial ROI')
roiManager.addRoi(roi)
# Create the table widget displaying
diff --git a/examples/scatterview.py b/examples/scatterview.py
new file mode 100755
index 0000000..cab32c0
--- /dev/null
+++ b/examples/scatterview.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+# coding: utf-8
+# /*##########################################################################
+#
+# Copyright (c) 2016-2019 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
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# ###########################################################################*/
+"""
+Example to show the use of :class:`~silx.gui.plot.ScatterView.ScatterView` widget.
+"""
+from __future__ import division
+
+__license__ = "MIT"
+
+import logging
+from silx.gui.plot.ScatterView import ScatterView
+from silx.gui import qt
+import numpy
+import scipy.signal
+
+
+logging.basicConfig()
+logger = logging.getLogger(__name__)
+
+
+def createData():
+ nbPoints = 200
+ nbX = int(numpy.sqrt(nbPoints))
+ nbY = nbPoints // nbX + 1
+
+ # Motor position
+ yy = numpy.atleast_2d(numpy.ones(nbY)).T
+ xx = numpy.atleast_2d(numpy.ones(nbX))
+
+ positionX = numpy.linspace(10, 50, nbX) * yy
+ positionX = positionX.reshape(nbX * nbY)
+ positionX = positionX + numpy.random.rand(len(positionX)) - 0.5
+
+ positionY = numpy.atleast_2d(numpy.linspace(20, 60, nbY)).T * xx
+ positionY = positionY.reshape(nbX * nbY)
+ positionY = positionY + numpy.random.rand(len(positionY)) - 0.5
+
+ # Diodes position
+ lut = scipy.signal.gaussian(max(nbX, nbY), std=8) * 10
+ yy, xx = numpy.ogrid[:nbY, :nbX]
+ signal = lut[yy] * lut[xx]
+ diode1 = numpy.random.poisson(signal * 10)
+ diode1 = diode1.reshape(nbX * nbY)
+ return positionX, positionY, diode1
+
+
+def main(argv=None):
+ """Display an image from a file in an :class:`ImageView` widget.
+
+ :param argv: list of command line arguments or None (the default)
+ to use sys.argv.
+ :type argv: list of str
+ :return: Exit status code
+ :rtype: int
+ :raises IOError: if no image can be loaded from the file
+ """
+ import argparse
+ import os.path
+
+ global app # QApplication must be global to avoid seg fault on quit
+ app = qt.QApplication([])
+ sys.excepthook = qt.exceptionHandler
+
+ mainWindow = ScatterView()
+ mainWindow.setAttribute(qt.Qt.WA_DeleteOnClose)
+ xx, yy, value = createData()
+ mainWindow.setData(x=xx, y=yy, value=value)
+ mainWindow.show()
+ mainWindow.setFocus(qt.Qt.OtherFocusReason)
+
+ return app.exec_()
+
+
+if __name__ == "__main__":
+ import sys
+ sys.exit(main(argv=sys.argv[1:]))
diff --git a/examples/simplewidget.py b/examples/simplewidget.py
index e952dc6..88977b7 100755
--- a/examples/simplewidget.py
+++ b/examples/simplewidget.py
@@ -44,6 +44,7 @@ from silx.gui.colors import Colormap
from silx.gui.widgets.WaitingPushButton import WaitingPushButton
from silx.gui.widgets.ThreadPoolPushButton import ThreadPoolPushButton
from silx.gui.widgets.RangeSlider import RangeSlider
+from silx.gui.widgets.LegendIconWidget import LegendIconWidget
class SimpleWidgetExample(qt.QMainWindow):
@@ -69,6 +70,10 @@ class SimpleWidgetExample(qt.QMainWindow):
layout.addWidget(self.createRangeSlider())
layout.addWidget(self.createRangeSliderWithBackground())
+ panel = self.createLegendIconPanel(self)
+ layout.addWidget(qt.QLabel("LegendIconWidget"))
+ layout.addWidget(panel)
+
self.setCentralWidget(main_panel)
def createWaitingPushButton(self):
@@ -122,6 +127,65 @@ class SimpleWidgetExample(qt.QMainWindow):
widget.setGroovePixmapFromProfile(background, colormap)
return widget
+ def createLegendIconPanel(self, parent):
+ panel = qt.QWidget(parent)
+ layout = qt.QVBoxLayout(panel)
+
+ # Empty
+ legend = LegendIconWidget(panel)
+ layout.addWidget(legend)
+
+ # Line
+ legend = LegendIconWidget(panel)
+ legend.setLineStyle("-")
+ legend.setLineColor("blue")
+ legend.setLineWidth(2)
+ layout.addWidget(legend)
+
+ # Symbol
+ legend = LegendIconWidget(panel)
+ legend.setSymbol("o")
+ legend.setSymbolColor("red")
+ layout.addWidget(legend)
+
+ # Line and symbol
+ legend = LegendIconWidget(panel)
+ legend.setLineStyle(":")
+ legend.setLineColor("green")
+ legend.setLineWidth(2)
+ legend.setSymbol("x")
+ legend.setSymbolColor("violet")
+ layout.addWidget(legend)
+
+ # Colormap
+ legend = LegendIconWidget(panel)
+ legend.setColormap("viridis")
+ layout.addWidget(legend)
+
+ # Symbol and colormap
+ legend = LegendIconWidget(panel)
+ legend.setSymbol("o")
+ legend.setSymbolColormap("viridis")
+ layout.addWidget(legend)
+
+ # Symbol (without surface) and colormap
+ legend = LegendIconWidget(panel)
+ legend.setSymbol("+")
+ legend.setSymbolColormap("plasma")
+ layout.addWidget(legend)
+
+ # Colormap + Line + Symbol
+ legend = LegendIconWidget(panel)
+ legend.setColormap("gray")
+ legend.setLineStyle("-")
+ legend.setLineColor("white")
+ legend.setLineWidth(3)
+ legend.setSymbol(".")
+ legend.setSymbolColormap("red")
+ layout.addWidget(legend)
+
+ return panel
+
def main():
"""