6.1. Quick tutorial to plots and figures¶
6.1.1. 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 then 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 if it is not able to plot the type of data object, itom falls back to the default plot plugin (and prints a warning into the console):
plot(data1d, "itom1DQwtPlot") #case insensitive plot class name
The result of both examples looks like this (if no other default plot class has been chosen for 1D static plots):
![../_images/plot1d.png](../_images/plot1d.png)
Instead of writing the full class name of a plot plugin that you want to use, you can also set the parameter className to some short-hand aliases. Depending on the alias, the default plot class (see itom’s property dialog) is chosen. Possible aliases are:
dataObject: 1D, 2D, 2.5D
pointCloud: 2.5D
polygonMesh: 2.5D
Example:
plot(data1d, '1D') #plot data1d in default plot for 1D, static plots
In the following sections, you will see that any plot has various properties that can be set in the property dialog or using square brackets in Python. However, you can also
pass various properties to the plot()
command such that your customized plot is displayed.
plot(data1d, properties={"title":"my user defined title","lineWidth":3, \
"lineStyle":"DashLine","legendPosition":"Bottom", \
"legendTitles":"my curve"})
Then, the plot looks like thies:
![../_images/plot1d_with_properties.png](../_images/plot1d_with_properties.png)
Passing a dictionary with various properties works with all types of plots. However, the list of available properties might change and can be obtained either using the Python
command info()
or displaying the properties toolbox of the plot. For more information see also Properties of plots below.
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](../_images/plot2d.png)
If you not only work with data objects but also with numpy you can also pass numpy arrays to the plot()
command. An implicit shallow
copy in terms of a itom.dataObject
is then created and passed to the plots.
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.
6.1.2. 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 are implemented as 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:
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.
The command
startDevice()
of the camera is called (idle command if the camera is already started)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.
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) #can be omitted if auto grabbing already enabled
liveImage(cam)
The command itom.liveImage()
has almost the same arguments than itom.plot()
. You can also set a desired plot plugin using the argument className.
Similar to the command itom.plot()
, described above, there are also aliases available that describe the desired plot style of the camera’s live image:
dataObject: 1D, 2D
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](../_images/liveImageGUI.png)
6.1.3. 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 customized dialogs, windows and dock widgets.
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"})