Sample Code

All sample codes can be downloaded as a zip file: silx_examples.zip.

silx.gui sample code

silx.gui.icons

Source

Screenshot

Description

icons.py

../_images/icons.png

Display icons and animated icons provided by silx.

silx.gui.data and silx.gui.hdf5

Source

Screenshot

Description

customHdf5TreeModel.py

../_images/customHdf5TreeModel.png

Qt Hdf5 widget examples

customDataView.py

../_images/customDataView.png

Qt data view example

hdf5widget.py

../_images/hdf5widget.png

Qt Hdf5 widget examples

silx.gui.dialog

Source

Screenshot

Description

fileDialog.py

../_images/fileDialog.png

Example for the use of the ImageFileDialog.

colormapDialog.py

../_images/colormapDialog.png

This script shows the features of a ColormapDialog.

silx.gui.widgets

Source

Screenshot

Description

periodicTable.py

../_images/periodicTable.png

This script is a simple example of how to use the periodic table widgets, select elements and connect signals.

simplewidget.py

../_images/simplewidget.png

This script shows a gallery of simple widgets provided by silx.

It shows the following widgets:

silx.gui.plot sample code

Widgets

Source

Screenshot

Description

imageview.py

../_images/imageview.png

Example to show the use of ImageView widget.

It can be used to open an EDF or TIFF file from the shell command line.

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

stackView.py

../_images/stackView.png

This script is a simple example to illustrate how to use the StackView widget.

scatterview.py

../_images/scatterview.png

Example to show the use of ScatterView widget

compareImages.py

../_images/compareImages.png
usage: compareImages.py [-h] [–debug] [–testdata] [–use-opengl-plot]

[files [files …]]

Example demonstrating the use of the widget CompareImages

positional arguments:
files Image data to compare (HDF5 file with path, EDF files,

JPEG/PNG image files). Data from HDF5 files can be accessed using dataset path and slicing as an URL: silx:../my_file.h5?path=/entry/data&slice=10 EDF file frames also can can be accessed using URL: fabio:../my_file.edf?slice=10 Using URL in command like usually have to be quoted: “URL”.

optional arguments:
-h, --help

show this help message and exit

--debug

Set logging system in debug mode

--testdata

Use synthetic images to test the application

--use-opengl-plot

Use OpenGL for plots (instead of matplotlib)

imageStack.py

../_images/imageStack.png

Simple example for using the ImageStack.

In this example we want to display images from different source: .h5, .edf and .npy files.

To do so we simple reimplement the thread managing the loading of data.

silx.gui.plot.actions.PlotAction

Sample code that adds buttons to the toolbar of a silx plot widget.

Source

Screenshot

Description

plotClearAction.py

../_images/plotClearAction.png

This script shows how to create a minimalistic PlotAction that clear the plot.

This illustrates how to add more buttons in a plot widget toolbar.

shiftPlotAction.py

../_images/shiftPlotAction.png

This script is a simple (trivial) example of how to create a PlotWindow, create a custom PlotAction and add it to the toolbar.

The action simply shifts the selected curve up by 1 unit by adding 1 to each value of y.

fftPlotAction.py, fft.png

../_images/fftPlotAction.png

This script is a simple example of how to create a PlotWindow with a custom PlotAction added to the toolbar.

The action computes the FFT of all curves and plots their amplitude spectrum. It also performs the reverse transform.

This example illustrates:
  • how to create a checkable action

  • how to store user info with a curve in a PlotWindow

  • how to modify the graph title and axes labels

  • how to add your own icon as a PNG file

See shiftPlotAction.py for a simpler example with more basic comments.

Add features to PlotWidget

Sample code that adds specific tools or functions to PlotWidget.

Source

Screenshot

Description

plotWidget.py

../_images/plotWidget.png

This script shows how to create a custom window around a PlotWidget.

It subclasses QMainWindow, uses a PlotWidget as its central widget and adds toolbars and a colorbar by using pluggable widgets:

plotItemsSelector.py

../_images/plotItemsSelector.png

This example illustrates how to use a ItemsSelectionDialog widget associated with a PlotWidget

plotInteractiveImageROI.py

../_images/plotInteractiveImageROI.png

This script illustrates image ROI selection in a PlotWidget

It uses RegionOfInterestManager and RegionOfInterestTableWidget to handle the interactive selection and to display the list of selected ROIs.

printPreview.py

../_images/printPreview.png

This script illustrates how to add a print preview tool button to any plot widget inheriting PlotWidget.

Three plot widgets are instantiated. One of them uses a standalone PrintPreviewToolButton, while the other two use a SingletonPrintPreviewToolButton which allows them to send their content to the same print preview page.

scatterMask.py

../_images/scatterMask.png

This example demonstrates how to use ScatterMaskToolsWidget and NamedScatterAlphaSlider with a PlotWidget.

plotCurveLegendWidget.py

../_images/plotCurveLegendWidget.png

This example illustrates the use of CurveLegendsWidget.

CurveLegendsWidget display curves style and legend currently visible in a PlotWidget

plotStats.py

../_images/plotStats.png

This script is a simple example of how to add your own statistic to a StatsWidget from customs Stats and display it.

On this example we will:

  • show sum of values for each type

  • compute curve integrals (only for ‘curve’).

  • compute center of mass for all possible items

Note

for now the possible types manged by the Stats are (‘curve’, ‘image’, ‘scatter’ and ‘histogram’)

plotProfile.py

../_images/plotProfile.png

Example illustrating the different profile tools.

PlotWidget features

Sample code that illustrates some functionalities of PlotWidget.

Source

Screenshot

Description

plotContextMenu.py

../_images/plotContextMenu.png

This script illustrates the addition of a context menu to a PlotWidget.

This is done by adding a custom context menu to the plot area of PlotWidget: - set the context menu policy of the plot area to Qt.CustomContextMenu. - connect to the plot area customContextMenuRequested signal.

The same method works with PlotWindow, Plot1D and Plot2D widgets as they inherit from PlotWidget.

For more information on context menus, see Qt documentation.

plotLimits.py

../_images/plotLimits.png

This script is an example to illustrate how to use axis synchronization tool.

plotUpdateCurveFromThread.py

../_images/plotUpdateCurveFromThread.png

This script illustrates the update of a silx.gui.plot widget from a thread.

The problem is that plot and GUI methods should be called from the main thread. To safely update the plot from another thread, one need to execute the update asynchronously in the main thread. In this example, this is achieved with submitToQtMainThread().

In this example a thread calls submitToQtMainThread to update the curve of a plot.

plotUpdateImageFromThread.py

../_images/plotUpdateImageFromThread.png

This script illustrates the update of a silx.gui.plot widget from a thread.

The problem is that plot and GUI methods should be called from the main thread. To safely update the plot from another thread, one need to execute the update asynchronously in the main thread. In this example, this is achieved with submitToQtMainThread().

In this example a thread calls submitToQtMainThread to update the curve of a plot.

syncaxis.py

../_images/syncaxis.png

This script is an example to illustrate how to use axis synchronization tool.

compositeline.py

../_images/compositeline.png

Example to show the use of markers to draw head and tail of lines.

dropZones.py

../_images/dropZones.png

Example of drop zone supporting application/x-silx-uri.

This example illustrates the support of drag&drop of silx URLs. It provides 2 URLs (corresponding to 2 datasets) that can be dragged to either a PlotWidget or a QLable displaying the URL information.

exampleBaseline.py

../_images/exampleBaseline.png

This example illustrates some usage possible with the baseline parameter

syncPlotLocation.py

../_images/syncPlotLocation.png

This script is an example to illustrate how to use axis synchronization tool.

silx.gui.plot3d sample code

Source

Screenshot

Description

plot3dSceneWindow.py

../_images/plot3dSceneWindow.png

This script displays the different items of SceneWindow.

It shows the different visualizations of SceneWindow and SceneWidget. It illustrates the API to set those items.

It features:

  • 2D images: data and RGBA images

  • 2D scatter data, displayed either as markers, wireframe or surface.

  • 3D scatter plot

  • 3D scalar field with iso-surface and cutting plane.

  • A clipping plane.

plot3dUpdateScatterFromThread.py

../_images/plot3dUpdateScatterFromThread.png

This script illustrates the update of a SceneWindow widget from a thread.

The problem is that GUI methods should be called from the main thread. To safely update the scene from another thread, one need to execute the update asynchronously in the main thread. In this example, this is achieved with submitToQtMainThread().

In this example a thread calls submitToQtMainThread to append data to a 3D scatter.

plot3dContextMenu.py

../_images/plot3dContextMenu.png

This script adds a context menu to a silx.gui.plot3d.ScalarFieldView.

This is done by adding a custom context menu to the Plot3DWidget:

  • set the context menu policy to Qt.CustomContextMenu.

  • connect to the customContextMenuRequested signal.

For more information on context menus, see Qt documentation.

viewer3DVolume.py

../_images/viewer3DVolume.png

This script illustrates the use of silx.gui.plot3d.ScalarFieldView.

It loads a 3D scalar data set from a file and displays iso-surfaces and an interactive cutting plane. It can also be started without providing a file.

silx.io sample code

Source

Screenshot

Description

writetoh5.py

This script is an example of how to use the silx.io.convert module. See the following tutorial for more information: Converting various data files to HDF5

silx.image sample code

Source

Screenshot

Description

findContours.py

../_images/findContours.png

Find contours examples

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.

silx.app sample code

Source

Screenshot

Description

customSilxView.py

../_images/customSilxView.png

Sample code illustrating how to custom silx view into another application.