It is common for users to annotate their graphs with metadata. While you could simply create static text objects, it is much more useful to create text objects that are dynamically linked to metadata so that your annotations update when your data change. Since these linked text objects are saved with the graph template this is an attractive option for those who routinely plot similarly-structured data. This blog post will show you how to create text objects that are linked to metadata in the same column as your plotted data; metadata from columns that were not plotted; or metadata from any data cell in the worksheet.
If you would like to follow along, you can download the file DOC-2238_Annotate_w_Metadata_blogpost. Unzip the file and open the OPJ file in your Origin workspace.
In this example, we have imported a .CSV file into an Origin worksheet.
- Columns 1, 2 and 3 contain imported data. Columns were assigned new Short Names.
- A user-defined parameter we call Start Time records the starting time of data acquisition and is saved in column 1.
- Two new columns are added to the worksheet.
- Column A(X2) — we use the Set Values feature to add the Start Time (start) to each value in column Time (X1). Note that the column Plot Designation of A is X (the “2” simply denotes this is as the second X column in the worksheet).
- Column B(Y2) — we use Set Values to subtract Reference column values from Sample column values. Note that the Plot Designation of B is Y.
- A second User-defined parameter row – Note – contains additional information (metadata): Adjusted Time (column A) and Sample – Reference (column B).
- We have two graph windows with plots of column B against column A. Graph2 is the final graph, annotated with worksheet metadata. Graph1 contains only the plotted data. It is to this graph that we will add our annotations.
To annotate the graph with metadata from the same worksheet column as your plotted data:
- Right-click in a blank area in the upper-right corner of the Graph1 page and choose Add Text… This puts you into in-place edit mode in a new text object.
- Press CTRL+H to open the Insert Variables dialog box.
- Select Y – Intensity in the right panel so that we can add metadata from the Y data column. Highlight Note = Sample Reference in the left-panel, make sure that Link with Plot Index is selected, clear the Insert as “Property = Value” box and click Insert. The string %(1Y, @LD2) is inserted into our text object. This notation refers to the Y data column of the first plot in the layer (there is only one plot) “at” row = User-defined parameter2 (which we have named Note). For 2D graphs.
- Click the Close button.
- Click outside the text object to exit edit mode. You will see that the label Sample – Reference is now added to the graph.
To annotate the graph with metadata from worksheet columns that were not plotted:
The Insert Variables dialog pictured above can only be used to insert metadata from plotted data. Therefore, if we wish to add metadata from columns that were not plotted, we need to manually create the text object using LabTalk substitution notation.
- Double click on Sample – Reference to enter in-place edit mode.
- Press ENTER to start a new line and type Measurement Start Time: %(1,@WT, Time, D1). The @WT option is used to get the value in any cell in the worksheet with the plot, so our notation refers to the worksheet of the 1st plot (again, we have only one plot), the Time column and the row of the first User-defined parameter, D1 or Start Time. This cell contains our time value 09:23:02.
Note: 1 in the notation, refers to the 1st plot. We can also use 1Y to refer to the Y data of 1st plot, or 1X to refer to the X data of the 1st plot but usually X, Y data of the plot are from the same worksheet so we don’t need to use 1Y or 1X when using @wt. Also in 2D graph, 1 is same as 1Y. For 3D graph, 1 is the same as 1Z.
To annotate the graph with metadata from any cell in the worksheet
- Press ENTER to start a new line in our text object and enter 1st Reference Value: $(%(1,@WT, 2, 1), .2). This notation is similar to the previous line of our text object but refers to worksheet column 2, row 1 of the data portion of the worksheet (the cell highlighted in light cyan in the worksheet). Further, we are modifying the value in that cell with $( ,.2) so that it displays as “.2” (with 2 decimal places). Note: To control display of significant digits, use the *n notation. For information on this and other format options, see this table on Default Formats.
- Click outside the text label to exit edit mode and you should see something like this (underlining can be added using the Format toolbar):
The expressions that we entered, both manually and using the Insert Variables dialog box, have been substitution processed and now show plain text in place of the variable notation. At this point, if you were to save your graph as a template, then import a new and identically-structured data file and plot it, you would see that your text label is updated with new information about your data file.
Notes on Substitution Notation
Before closing, we need to point out that there is one more critical step involved in creating these dynamically-linked text objects. Because we began this exercise by inserting a variable from the Insert Variables dialog box, this step was done for us. In cases where we do not open this dialog, we will need to make sure that we do the following before saving our template file.
- Return to Graph1, right-click on your text object and choose Programming Control. (Note: In case you are in 3D graph, Programming Control context menu may be grayed out in some versions. In such case, press Alt key and double click the text can open Programming Control dialog.
- You will see that Link to (%,$), Substitution Level is set to 1. If you are creating text labels manually, it is imperative that you open this dialog by right-clicking on your text object and set this control to 1 (there are cases where you need to choose a higher level but we won’t concern ourselves with that today). If you do not complete this step, the notation that you entered in your text object will not be substitution-processed (To see what would happen, set the Substitution Level to 0 and close the dialog box).
Secondly, we should point out that the same substitution notation can be used to customize the graph legend text. See a detailed explanation and complete list of options under Legend Text Customization and Worksheet Cell Access on this page.
Thanks for reading. We hope that this has been helpful. For further reading, we suggest these topics in our online documentation: