# 3.9.7 Legend Substitution Notation

## Origin Graph Legends

There are four standard legends for Origin graphs:

• Data Plot Legend: The default legend for most 2D and 3D graphs combines a plot symbol with legend text derived from column metadata (e.g. column Long Name).
• Categorical Values Legend: Legend entries combine a plot symbol -- one for each category within a column of worksheet data -- with the text that names the category. Categorical legends can depict multiple categorical variables (multiple columns of categorical data), with symbol variations listed by categorical variable.
• Box Chart Components Legend: Legend entries typically combine a plot symbol with a column metadata or category label, plus a symbolic list of displayed statistics.
• Point-by-Point Legend: A legend that combines a plot symbol with a number (the number can be a plot index number or a data value). Since every data point generates a legend entry, this legend type is most suited to certain plot types (e.g. Piper Diagrams) and small datasets.

The following information is presented to help you understand the variable syntax behind the various legends and, when necessary, to help you to modify legend object content.

## Data Plot Legend (most 2D and 3D graphs)

For most 2D and 3D graphs, the legend is constructed using the following substitution syntax:

Plot Symbol Component: \L([LayerIndex.]PlotIndex[,PointIndex[,option]])
Text Component: %(LayerIndex.PlotIndex[Axis, @option])

This can be seen in the user interface when you right-click on a selected legend object and choose Properties: Two things to note:

• The symbol component is enclosed by \L() and the text component is enclosed by %().
• Square brackets in the syntax model merely indicate an optional argument; you do not type the square bracket.

### Plot Symbol Component

This notation is used to construct the legend's data plot symbol, by displaying the symbol of the specified data plot. LayerIndex is optional but if omitted, the active layer is assumed. Additionally,the optional PointIndex is used to display the symbol assigned to a special data point.

#### Basic Syntax:

\L([LayerIndex.]PlotIndex[,PointIndex[,Option]])

where...

• LayerIndex(optional): The layer of the specified data plot, indexed from 1. For the active layer, this option can be omitted, as in \L(PlotIndex).
• PlotIndex: The data plot's position (indexed from 1) in the data list at the bottom of the Data menu or in Layer Contents. Note: this list is for all plots in the active graph layer.
• PointIndex(optional): If a single point in a dataplot has been customized, this option is used to display the custom symbol.

#### Options

Note that most options are specific to certain families of plots (e.g. Size applies to plot symbols).

Keyword Syntax Options
\L([LayerIndex.]PlotIndex[,PointIndex[,Option]]) 1=Show Border or Edge color as a block, 2=Show Interior color as a block, 3=Show Pattern Color (or Black) as a block, 4=Show empty Symbol (or special Not Used), 5=Not Used, 6=Not Used, 7=Show actual style.
Size \L([LayerIndex.]PlotIndex[,PointIndex][,Size:Option]) Size:## displays a scatter symbol at specific point size or Size:p## percentage of plot symbol size (can be > 100%).
Style \L([LayerIndex.]PlotIndex[,PointIndex][,Style:Option]) Style:## displays a sequence of symbols and/or line segments, where s=symbol, l=line segment. Can be listed in any order (e.g. "Style:sls" displays as symbol/line segment/symbol).
Gap \L([LayerIndex.]PlotIndex[,PointIndex][,Gap:Option]) Gap:## sets the line to symbol gap in point size, Gap:p## displays the gap as a percentage of default.
Fill \L([LayerIndex.]PlotIndex[,PointIndex][,Fill:Option]) Fill:## sets the interior color on hollow symbols. Works with LabTalk color index or with html color codes.
EdgeColor \L([LayerIndex.]PlotIndex[,PointIndex][,EdgeColor:Option]) EdgeColor:## sets the interior color on solid symbols. Works with LabTalk color index or with html color codes.
EdgeWidth \L([LayerIndex.]PlotIndex[,PointIndex][,EdgeWidth:Option]) EdgeWidth:## sets symbol edge thickness in point size, EdgeWidth:p##displays the thickness as a percentage of plot symbol edge width (can be > 100%).
LineColor \L([LayerIndex.]PlotIndex[,PointIndex][,LineColor:Option]) LineColor:## sets line color. Works with LabTalk color index or with html color codes.
LineWidth \L([LayerIndex.]PlotIndex[,PointIndex][,LineWidth:Option]) LineWidth:## sets line width in point size. LineWidth:p## displays line width as a percentage of plot line size (can be > 100%).
Length \L([LayerIndex.]PlotIndex[,PointIndex][,Length:Option]) Length:## sets line length in point size; Length:p## displays it as a percentage of width of active dataset indicator (can be > 100%).
Width \L([LayerIndex.]PlotIndex[,PointIndex][,Width:Option]) Width:p## sets block width as percentage of active dataset indicator] (max value = 100%).
Height \L([LayerIndex.]PlotIndex[,PointIndex][,Height:Option]) Height:p## sets block height as percentage of active dataset indicator (max value = 100%).
Pattern \L([LayerIndex.]PlotIndex[,PointIndex][,Pattern:Option]) Pattern:## sets Pattern by index number, starting from 1.
PatternFill \L([LayerIndex.]PlotIndex[,PointIndex][,PatternFill:Option]) PatternFill:## sets column/bar graph interior color. Works with LabTalk color index or with html color codes.
BorderColor \L([LayerIndex.]PlotIndex[,PointIndex][,BorderColor:Option]) BorderColor:## sets column/bar graph border color. Works with LabTalk color index or with html color codes.
BorderThick \L([LayerIndex.]PlotIndex[,PointIndex][,BorderThick:Option]) BorderThick:## sets border thickness as a multiple of default thickness. You can apply multiple plot symbol modifiers by leaving spaces between options: \l(1,BorderColor:2 borderthick:2 pattern:3 patternheight:p50) %(1)

### Text Component

Legend text can be created using literal text (manually) but the more usual and efficient method relies on substitution notation -- use of LabTalk variables to display metadata associated with the dataplot. These metadata can be accessed by specifying an "@" option and can be used to override default legend construction behavior specified in the Legends/Titles tab in the graph's Plot Details dialog box. As previously mentioned, square brackets denote optional arguments and are not typed when constructing the legend text.

#### Basic Syntax

%([LayerIndex.]PlotIndex[Axis[, @option]])

where...

• LayerIndex(optional): The layer of the specified data plot, indexed from 1. For the active layer, this option can be omitted, as in \L(PlotIndex).
• PlotIndex: The data plot's position (indexed from 1) in the data list at the bottom of the Data menu or in Layer Contents. Note: this list is for all plots in the active graph layer.
• Axis: For the specified layer and plot, X, Y or Z, indicates which column of the source data will be referred to. If not specified (default), it is assumed to be Y for 2D graphs, and Z for 3D graphs.
• @option: This option can be used to override the default Auto Legend Translation Mode that is saved with the graph template. See the Legend Text Customization section of this page for a list of @options related to graph legends.

### Examples

Legend Entry Description
Legend of Specific Plot/Symbol

\l(1) %(1)
\l(2) %(2)

Both lines are the legends for the data plots in the active layer. The first line is for the first plot, and the second line for the second plot.

Based on the typical default specified in the Legends/Titles tab in the Plot Details dialog of the graph, the legend's label will look for Comments in the source data worksheet, if no Comments then Long Name will be used, and if no Long Name, Short Name is used.

\l(1.1) %(1.1)
\l(2.1) %(2.1)

The first line is the legend for the first plot in the first layer, and the second line for the first plot in the second layer.

\l(1) %(1, @LD1)
\l(1) %(1Y, @LD1)
\l(1) %(1, @LD"UserP Name")

The legend symbol is from the first plot in the active layer, and the legend's label is from the first User Parameter row of the Y column in the source data worksheet. Identical for 2D plots since Y is optional. Note that you can refer to parameter by user-parameter row number or name (if spaces, contain in double-quotes).

\l(1) %(1X, @L)

The legend symbol is from the first plot in the active layer, and the legend's label is from the Long Name of the X column in the source data worksheet.

\l(2.3,5) %(2.3X, @LU) Lowest Value

The legend symbol is from the fifth point in third plot in the second layer, and the legend's label is from the Units of the X column in the source data worksheet plus additional user-supplied text: Lowest Value.

\l(1,3,2) %(1)

The legend symbol is from the 3rd symbol in the active layer, and the plot element used is the interior color.

Legend Entry Description Example
Legend of Partial Property of Symbol
\l(1) ) %(1) Original line+symbol plot \l(1, style:s) ) %(1) Show symbol only for a line + symbol plot \l(1,style:l) %(1) Show line only for a line + symbol plot \l(1,style:sls) Show legend as symbol - line- symbol for a line + symbol plot Legend Entry Description Example
Legend of Scaled Symbols
\l(1) ) %(1) Original line+symbol plot \l(1,size:5) %(1) Show symbol size 5 \l(1,size:p150) %(1) Scale symbol size as 150% of original symbol size \l(1, LineWidth:3) %(1) Show line width as 3 \l(1, LineWidth:p1000) %(1) Show line width as 1000% of original line width \l(1, Length:p50 %(1) Show line length as 50% of original length \l(1) ) %(1) Original column plot \l(1, PatternHeight:p50) %(1) Show bar height as 50% of original height \l(1, PatternWidth:p50) %(1) Show bar width as 50% of original width Legend Entry Description Example
Legend of Bar Elements
\l(1) Bar Original bar plot (1st bar of 1st layer) \l(1, style:C) Fill Color Show fill color of Bar \l(1,1,2) Fill Color Show fill color of the 1st bar of 1st layer in a block \l(1, style:P) Pattern Show Pattern Style of Bar \l(1,style:P#81F7F3) Custom Fill Color Show legend of fill with custom color \l(1,1,1) Border Color Show border color of the 1st bar of 1st layer in a block \l(1,1,3) Pattern Color Show pattern color of the 1st bar of 1st layer in a block Notes:

## Adding Symbols Not Used in Plots

While it requires some patience, you can create a legend symbol with no relationship to plotted data.

The following four kinds of syntax can be used in different occasions, depending on what kind of symbols you would like to use.

 \L(O SymEdgeColor,Sym,Fill,Size,ColorLn,LineStyle,Gap,LnWidth,SymFillColor,EdgeThickness) \L(S 0, Sym, Fill, SymEdgeColor, SymFillColor, Size, LineStyle, ColorLn, LnWidth, Gap, EdgeThickness) \L(S 1, SymIndex, SymEdgeColor, Size, , , LineStyle,ColorLn, LnWidth, Gap) \L(S 1,CharIndex,CharColor,Size,Font,FontStyle,LineStyle,ColorLn, LnWidth, Gap)

Note: For the \L(S ) type of syntax, defining the first variable as 0 means to use an Origin built-in symbol, and defining it as 1 means to use a user-defined symbol or an ASCII character.

The definition of each variable is listed below:

Argument Description
SymEdgeColor From Origin Color index: 1...24 (1=Black,2=Red, etc.) or 24...40 if user-defined colors exist.
From HTML hex code: e.g. #ff0000 (do not surround with double-quotes as is required when using with the color() function).
Sym Symbol to use from Origin Shape index (0=no symbol, 1=square, 2=circle, 3=up triangle, 4=down triangle, 5=diamond, 6=cross, 7=cross(x), 8=asterix, 9=hbar, 10=vbar, 11=number, 12=LETTER, 13=letter, 14=right arrow, 15=left triangle, 16=right triangle, 17=hexagon, 18=star, 19=pentagon, and 20=sphere).
Fill Fill to use in symbol from Origin Interior index (0=solid, 1=open, 2=dot center, 3=hollow, 4=plus center, 5=x center, 6= hbar center, 7=vbar center, 8=half up, 9=half right, 10=half down, and 11=half left).
Size Symbol Size in Points.
ColorLn From Origin Color index or from HTML hex code (see SymEdgeColor).
LineStyle Line Style from Origin Line Styles (0=Solid, 1=Dash, 2=Dot, 3=Dash Dot, 4=Dash Dot Dot, 5=Short Dash, 6=Short Dot, 7=Short Dash Dot).
Gap Gap between Symbol and Line in percent of Symbol Size.
LnWidth Line Thickness in Points.
SymFillColor From Origin Color index or from HTML hex code (see SymEdgeColor).
EdgeThickness Symbol Edge Thickness in percent from 0 to 100.
SymIndex The order of the user defined symbol in the User-defined Symbols Grid. Allow integer input from 1 to 31.
CharIndex The ASCII code of the character. Allow integer input from 32 to 255.
CharColor The color index of the ASCII character. (see SymEdgeColor).
Font The index number of a particular font in your font list. To get the index number for a font, run font(fontname)= in the Script Window or Command Window.
Font Style The index number of font style (Underline, Italic, Bold). 0=no style, 1= Underline only, 2=Italic only, 3=Underline+Italic, 4=Bold only, 5=Underline+Bold, 6=Italic+Bold, 7=Underline+Italic+Bold. When one variable is left as empty, the default value will be used for this variable. The syntax \L(O SymEdgeColor,Sym,Fill,) will use the default value for all variables after Fill. You can also use these worksheet cell access notations to define one of the variables using a worksheet cell value.

A simpler syntax is available to create a Line Legend Symbol.

\L(L Color, Thickness, Style)

Argument Description
Color Line Color from Origin Color index: 1..24 (1=Black, 2=Red, etc.) or 24..40 if user-defined colors exist.
Thickness Line Thickness in Points.
Style Line Style from Origin Line Styles (0=Solid, 1=Dash, 2=Dot, 3=Dash Dot, 4=Dash Dot Dot, 5=Short Dash, 6=Short Dot, 7=Short Dash Dot).

## Other Legend Customizations

### Special Formatting of Legend Text

You can also customize the text format by escape sequences. Several frequently used examples are provided below:

Use this syntax... ...to format text Example
\+(text) Superscript  %(1)\+(2)
\-(text) Subscript  %(1)\-(n)
\g(text) Greek Letters \g(m)
\b(text) Bold \b(Important)
\i(text) Italic \i(%(1))
\u(text) Underline \u(%(1X,@L))

### Legend Element Alignment

 Note: The information below may provide more flexibility in aligning legend elements. If you are simply interested in right-aligning legend text, see this FAQ.

To specify the alignment properties for symbol and text in legend, you need to activate the graph, and run the script below in Script Window:

legend.align=1;   //turn on the alignment mode

Then, you can right click the legend to select Properties to open the dialog, and add \^() as cell anchor, which set alignment for the object on the right side of anchor, \^(l), \^(c), \^(r) are LEFT, CENTER and RIGHT alignment respectively, for example: After clicking OK, the legend will be shown the same as the preview in dialog.

Alternatively, you can press Ctrl and drag to re-arrange the legend: For instance, you can make symbol C at the right side of symbol B by using Ctrl+drag. In this case, you need to use \^(lu), \^(cc), \^(ru) instead \^(l), \^(c), \^(r) between symbol and text: In this way, the symbol and corresponding text will be treated as one group when Ctrl+drag rearranging, as shown below: Otherwise, the symbol and corresponding text will be separated when Ctrl+drag rearranging: 