Quick tutorial to plots and figures

Plots of data objects

The most common way to plot an arbitrary data object is the plot() command contained in the module itom.

In the first example, we create an one-dimensional data object with random values (16bit, signed, fixed point precision) and simple want to visualize this data object in a line plot. itom is able to recognize the type of plot you desire and uses the plot plugin which is set to be default for this type of plot (static, line plot). The defaults can be set in the property dialog of itom.

data1d = dataObject.randN([1,100],'int16')
plot(data1d)

Note

Please consider that any one-dimensional data object is always exposed as two-dimensional data object, where the first (y) dimension is set to 1.

If you have various plot plugins available that can handle that type of data object, you can also force the plot command to use your specific plugin, which is defined by its class name (see itom’s property dialog for the class name). If the class name cannot be found or is not able to plot the type of data object, itom falls back to the default plot plugin:

plot(data1d, "Itom1DQwtPlot")

The result of both examples can be like this:

../_images/plot1d.png

Equivalent to the one-dimensional case, the following example shows how to simply plot a two-dimensional data object also using the command plot().

data2d = dataObject.randN([1024,768],'uint8')
plot(data2d)

Then, you obtain a figure that looks like this:

../_images/plot2d.png

If you not only work with data objects but also with numpy

If the plot is opened in its own figure window, you have a dock-button in the toolbar on the right side. Click on this button in order to dock the plot into the main window of itom.

Live images of cameras and grabbers

itom is not only able to plot data objects but can also show live streams of connected and opened cameras. Cameras can be all plugins of type dataIO that also have the grabber-type flag defined (see the section grabbers of your plugin toolbox in itom). If a live image of a specific camera should be created, the following process is started:

  1. The camera is asked for its parameters sizex and sizey. If one of these dimensions is equal to one, a live line image is opened, else a two-dimensional live image is opened.
  2. The command startDevice() of the camera is called (idle command if the camera is already started)
  3. A timer continuously triggers the image acquisition of the camera and sends the result to all currently connected live images. However the timer is not started or stopped whenever the auto-grabbing property of the camera is disabled. This is useful, if you are in the middle of measurement process. Then you don’t want the timer to force the image acquisition but your process. Therefore, disable to auto-grabbing property before starting your measurement and reset it to its previous status afterwards. In any case, whenever any prcoess triggers an image acquisition, all results will always be sent to connected live images.
  4. When the live plot is closed or deconnected, the command itom.dataIO.stopDevice() is called (this is again an idle command if the camera is still used by other live images or has been started by any python script and not stopped yet).

In the following example, the dummy grabber camera is started and the live image is opened using the command liveImage(). The auto-grabbing property is set to True (which is also the default case):

cam = dataIO("DummyGrabber")
cam.setAutoGrabbing(True)
liveImage(cam)

You can also show the live image of any camera using the GUI. Right-click on the opened camera instance in the plugin toolbox and choose live image:

../_images/liveImageGUI.png

Properties of plots

Any plots have properties defined, which indicate the appearance or currently depicted data object or camera. To access these cameras you need to get the instance of the plot or live image item. This is always an instance of the class plotItem. This class is inherited by uiItem which finally provides the access to the properties by the functionalities described in Creating advanced dialogs and windows.

In order to access the necessary instance of plotItem, you will see that the return value of the commands plot() or liveImage() is a tuple consisting of a number of the overall figure (window), where the plot is print and of the requested instance as second value.

In the next example, the title of a two-dimensional data object plot is changed:

data2d = dataObject.randN([100,100])
[idx,h] = plot(data2d)
h["title"] = "new title"

Note

Not all plot plugins have the same properties defined, since this also depends on their type and special features. However it is intended to use the same property names for the same meaning in the different plugins.

Note

If the figure closed while you still have a reference to its instance, any method of this instance will raise an error saying that the plot does not exist any more.

In order to get a list of all properties of a plot, call the method info() of the plot instance. This method prints a list of available properties as well as slots and signals.

h.info()

There are two other important properties that let you change the displayed data object or camera:

#set new data object
h["source"] = dataObject.randN([100,100])

#assign new camera
h["camera"] = dataIO("DummyGrabber")

These properties are also the way to set the content of plot widgets, that are integrated in your user-defined GUIs.

The properties can also be changed using the properties toolbox of each plot or live image that is accessible via the menu View >> Properties. Furthermore it is possible to directly set some properties by passing a dictionary with all name, values pairs to the ‘properties’ argument of commands plot() or liveImage():

plot(data2d, properties={"yAxisFlipped":True, "title":"My self configured plot"})

Table Of Contents

Previous topic

Plots and Figures

Next topic

Figure Management

This Page