This is an archived page, please click here to view the latest updates.

OriginLab Corporation - Scientific Graphing and Data Analysis Software - 2D graphs, 3D graphs, Contour Plots, Statistical Charts, Data Exploration, Statistics, Curve Fitting, Signal Processing, and Peak Analysis

Manual Control of the Graph Legend


The graph legend is a specialized Origin text object that uses a hidden variable notation to dynamically link to the workbook/worksheet data that it depicts. When a legend is created, Origin names the text label "Legend" in order to uniquely identify it and to ensure that the object behaves as a legend. The name of the legend object is visible in the legend's Programming Control dialog box (Format: Programming Control, with the legend object selected).

Image:Manual Control of the Graph Legend 01.png

Note, too, the Link to (%,$), Substitution Level drop-down list is 1, which allows the legend object to be dynamically linked to the source data.

Most users will find Origin's improved default legend display options to be sufficiently flexible as to make manual editing of the legend object unnecessary. However, if you wish to have more control over the graph legend display, you may find the following information to be helpful.

Contents

Renaming the legend object

Because the legend object is a specialized text object with a name ("Legend") that has particular significance inside Origin, you must rename it in order to preserve the customizations that are discussed in this section. Otherwise, any action that refreshes the legend object will likely overwrite your customizations. Once you rename the legend object, it becomes a static object and is no longer under Origin's control.

To rename the legend object:

  1. Click on the legend object to select it.
  2. From the menu, choose Format: Programming Control.
    or
    Right-click and choose Programming Control from the shortcut menu.
  3. Change Object Name to something other than "Legend," then click OK.

Changing the legend text

As mentioned, the default legend is created using a LabTalk variable notation. This notation can be seen, in part, when you double-click on the legend to enter edit mode. Once you are in edit mode, you simply highlight the text that you want to change and type over it.

Image:Manual Control of the Graph Legend 02.png

This is probably most useful in situations where you have customized the plot symbol of a single data point and you wish to add some explanatory text to the legend.

Understanding the legend's variable notation

To view the legend's variable notation in full, you must open the legend's Object Properties dialog box:

Right-click on the legend object and select Properties... from the shortcut menu.

In the Object Properties dialog box, the general notation for the legend display is:

\l(DataListPosition) %(DataListPosition)

Image:Manual Control of the Graph Legend 03.png

where the \l() switch creates the legend's data plot symbol and DataListPosition is the data plot's position in the data list at the bottom of the Data menu. This is a list of all plots in the active graph layer. Grouped data plots are preceded by a "g" in the plot list. The number following the letter "g" identifies the member of a group (since it is possible to have multiple groups within a layer).

Image:Manual Control of the Graph Legend 04.png

Creating a legend for different elements in a dataplot

The following syntax can be used to create a legend for different elements in a layer's dataplot.

\l(plot_index,element_index) text

where plot_index is the index of the dataplot in the current layer, and element_index is the index of the element in the dataplot.

It is useful to customize a legend in a dataplot with a dataset to control plot attributes, e.g. color, or a dataplot including customized elements.

For example, we use a category column Drug as the symbol's Indexing Color in a scatter plot, which includes three groups Drug A, Drug B, and Placebo. The categories for the 1st, 3rd, and 5th points are Drug A, Drug B, and Placebo, respectively.

Type the following syntax in the legend's Object Properties dialog box:

\l(1,1) Drug A

\l(1,3) Drug B

\l(1,5) Placebo

The legend would look like this:

Image:Legend_element.png?

Advanced legend text customizations

You can use the following @letter arguments to modify the %(DataListPosition) notation. For example, to modify the first legend entry so that it displays the data range notation, you could enter the following in the Object Properties dialog box:

\l(1) %(1,@D)

Below is a partial list of variable options for legend text (for a complete list of options, please refer to Text Label Options) :

Use this @letter argument... ...to display this text in the legend Example
@D Dataset name Book1_Mg
@R Dataset range [Book1]Data1!Col(Magnesium)[1:30]
@LA Long Name if available (otherwise Short Name) Magnesium
@LHn The row header of the nth User-Defined Parameter.

This notation is also supported for WorkSheet access. For example, the following notation

%([Book2]Sheet1,@LH2,1)

will show the row header name of the second User-Defined Parameter in Book2, Sheet1. The index "1" is needed since this notation on WorkSheet is column specific, but you can enter any column index that is valid.

Annealing Temperature
@LS Short Name Mg
@LQn The nth User-Defined Parameter + Unit if available Annealing Temperature (C)
@LL Long Name Magnesium
@LU Units (not including Long Name) (?g/ml)
@LC Comment if available, otherwise Long Name, otherwise Short Name trial run
@LCn The nth line of Comment say, there are two lines in the Comment of the first column:
Temperature
15C

%(1,@LC2) refers to the second line, that is, 15C.

@LPn Parameter n temp=15C
@LG Long Name if available (otherwise Short Name) + Unit Magnesium (?g/ml)
@LM Comment if available, otherwise Long Name, otherwise Short Name. trial run
@PCn The nth line of the WorkBook Comment. If n is not specified, all lines will show. Magnesium Measurement
@LN Comment if available (otherwise Long Name, otherwise Short Name) + Unit. trial run (?g/ml)
@WCn the nth line of the WorkBook Comment. If n is not specified, only the first line will show. Magnesium Measurement
@WMn the nth line of the WorkSheet Comment. If n is not specified, only the first line will show. Magnesium Measurement

Note that to use substitution notation (%,$) in an ordinary Origin label object, you must also set the Link to (%,$), Substitution Level to 1 in the Programming Control dialog box. In the case of the legend object, Link to (%,$), Substitution Level is 1 by default.

Image:Tip_icon.png

From Origin 9.0, it is possible to combine the text labels to form your user-defined label. For example to use "@LL[@LU]" means that the label is defined as "long name[unit]", and to use @LL-test-@LC means that the label is defined as "long name-test-comments".

Manually forming the legend's data plot symbols

  1. Using the following syntax, it is possible to construct a graph legend that displays plot symbols that are completely independent of the symbols used in the data plot:
    \L(O SymEdgeColor,Sym,Fill,Size,ColorLn,LineStyle,Gap,LnWidth,SymFillColor, EdgeThickness)
    where:
    SymEdgeColor determines the color of the symbol edge in the legend. The value typed here is the color index in Origin's color list. 1-24 correspond to the default 24 colors (1=Black, 2=Red, etc.), and 25 - 40 correspond to the user-defined colors.
    Sym determines the symbol shape in the legend. Type a value corresponding to the symbol shape, where 0 = no symbol, 1 = square, 2 = circle, 3 = up triangle, 4 = down triangle, 5 = diamond, 6 = cross (+), 7 = cross (x), 8 = star (*), 9 = bar (-), 10 = bar (|), 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 determines the symbol interior for the symbols in the legend. Type a value corresponding to the symbol interior, where 0 = solid, 1 = open, 2 = dot center, 3 = hollow, 4 = + center, 5 = x center, 6 = - center, 7 = | center, 8 = half up, 9 = half right, 10 = half down, and 11 = half left.
    Size determines the symbol size in the legend. Type a value for the symbol size in points.
    ColorLn determines the line color in the legend. The value typed here is the color index in Origin's color list. 1-24 correspond to the default 24 colors (1=Black, 2=Red, etc.), and 25 - 40 correspond to the user-defined colors.
    LineStyle determines the line style for the legend. Type a value corresponding to the line style sequence in the Style drop-down list on the Line tab of the Plot Details dialog box (0=Solid, 1=Dash, etc.).
    Gap determines the line and symbol gap in the legend. Type a gap value that corresponds to a % of the symbol diameter. For example, type 50 to display a gap between the symbol and the line (in the legend) which is 50% of the symbol diameter.
    LnWidth determines the line width for the legend. Type a value for the line width in points. A value of 0 results in no line display.
    SymFillColor determines the color of the symbol fill in the legend. The value typed here is the color index in Origin's color list. 1-24 correspond to the default 24 colors (1=Black, 2=Red, etc.), and 25 - 40 correspond to the user-defined colors.
    EdgeThickness controls the edge thickness of non-filled plot symbols. Type a value of 0 to 100% of the symbol's half-diameter (a setting of 100% will produce a filled symbol). If edge thickness is not specified or is -1, the default Symbol Border Width (%) combo box setting is used (see, The (Options) Graph tab in the Origin Help file for more information).
  2. You can also customize legend for line plots by using the following simpler syntax:
    \L(L Color,Thickness,Style)
    where:
    Color determines the line color in the legend. The value typed here is the color index in Origin's color list. 1-24 correspond to the default 24 colors (1=Black, 2=Red, etc.), and 25 - 40 correspond to the user-defined colors. Its default value is 1(black).
    Thickness determines the line width in the legend. The value typed here is corresponding to the Width value on the Line tab of the Plot Details dialog. Its default value is 0.5.
    Style determines the line style in the legend. The value typed here is corresponding to the line style sequence in the Style drop-down list on the Line tab of the Plot Details dialog. Its default value is 0(solid).
  3. The following syntax is used to show the symbol shapes or interior patterns in legend:
    \L(layer_index, plot_index, nn)
    When nn=4, the legend shows the symbol shapes; when nn=5, the legend shows the interior patterns.
  4. The following two syntaxes are used to specify the symbol size in the legend independent of the symbol size of the data plots.
    1. Directly specify the symbol size in the legend:
      \L(DataListPosition,s:##)
      Where DataListPosition is the data plot's position in the data list at the bottom of the Data menu, and s:## determines the symbol size in the legend.
      Please note that s:## can be in the second and third position. For example, both L(1,s:10) and L(1,15,s:10) can set the symbol size to 10.
      The symbol size specified by this syntax will still be confined to the bounding rectangle of the legend.
    2. Define the symbol size as percentage of the legend rectangle box:
      \L(DataListPosition,s:p##)
      Where DataListPosition is the data plot's position in the data list at the bottom of the Data menu, and s:p## specifies the symbol size as percentage of the legend rectangle box. It will be resized as you resize the legend rectangle.
      Please note that the look and actual symbol size will depend on the symbol shape. Suppose that the symbol size has been set to "s:p100". The square symbol will not reach the rectangle box, while one of the angles of a triangle will be out of the box.
      In contrast to the first syntax, the symbol size greater than 100% of the rectangle box is not prohibited. However, the symbol may eventually overlap with other legend symbols if more than one plot exists in the layer.