How do I add a second x or y axis to my graph that displays a nonlinear relationship to my primary axis?

     

How do I add a second x or y axis to my graph that displays a nonlinear relationship to my primary axis?

With scientific and engineering data, it is often necessary to add a second x or y axis to a graph layer where the second axis displays a nonlinear relationship to the first axis. The second axis may become necessary for instance to display the same quantity in different units, such as temperature in Fahrenheit instead of Celsius, energy (ev) instead of wavelength (nm) etc.

With a simple linear axis relationship such as Celsius to Fahrenheit (F = (9/5) * C + 32), this can be achieved by adding a second layer and using the "Link Axis Scales" tab in the Plot Details dialog box on the second layer.

The methods listed below work for any formula and are not thus restricted to a linear relationship. Both methods work for setting up either an X or Y axis relationship. We will follow a simple example of setting up a nonlinear relationship of x2 = 1/x1.



Method I – Second axis has ticks at the same position as first axis

(Requires Origin 7.5 or higher)

In this method, the tick mark positions on the second axis will appear exactly at the same location on the layer as the tick marks of the first axis. The benefit is that one can see the exact value on the second axis for each value displayed in the first axis. The drawback is that the numbers or labels shown on the second axis may not be nicely spaced or nicely rounded off.

Example - Equi-spaced Ticks
You can create a graph like below:

Steps:

1. Start a new worksheet and fill columns 1 and 2 with the following data:
(Please note that this is arbitrary data and does not have any particular significance to this method.)
Column 1:
5.1, 6.7, 7.8, 8.7, 9.8, 10.9, 12.2, 13.3
Column 2:
2, 4, 7, 5, 4, 3, 6, 8

2. Create a Line & Symbol graph of the data.

3. In the graph window, double-click on the bottom X axis tick labels to open the X Axis dialog. In the Selection panel on the left of the dialog, select Top and then turn on the display of labels and axis ticks.
The top X axis will now display same labels as the bottom one.
(You can turn on the top axis from the script window as well using the commands: layer.x.showaxes=3; layer.x.showlabels=3;)

4. Open the script window (menu command Window | Script Window) and type the following line of command and press Enter:
  layer.x2.label.formula$ = "1/x"

This will place labels on the top x axis at the exact same location as the bottom x axis, with values computed by the specified formula.
Double-click on the top axis tick labels and in the Tick Labels tab of the Axis dialog, check the Set Decimal Places check box and enter the number 3 in the edit box.

Note that the formula in step 4 above can be any string that is a function of x and is calculable using LabTalk script.

Similar to adding a second X axis on top, you can add a second Y axis on the right by turning on the right Y axis display and using the script command:
  layer.y2.label.formula$ = "1/x"

Note that even though you are setting the Y axis in the command above, the formula still needs to be specified in terms of "x" and not "y".


Method II – User specifies/controls the position of the ticks on the second axis

(Requires Origin 7.0 SR2 or higher)

In this method, the labels on second axis can be nicely spaced and rounded off. The user specifies the exact location and label value. The drawback is that a second layer needs to be added, and further, the tick label position and content for the second axis will need to be updated by hand if for instance the scale of the first axis is changed significantly.

Example - Nonequi-spaced Ticks
You can create a graph like below:

Steps:

1. Start a new worksheet and fill columns 1 and 2 with the following data:
(Please note that this is arbitrary data and does not have any particular significance to this method.)
Column 1:
5.1, 6.7, 7.8, 8.7, 9.8, 10.9, 12.2, 13.3
Column 2:
2, 4, 7, 5, 4, 3, 6, 8

2. Create a Line & Symbol graph of the data.

3. Select the Edit|New Layer(Axes)|(Linked) Top X menu command to add a second layer with the X axis displayed on top. At this point the tick labels on the top X axis will have no relationship to the bottom axis.

4. Select the Format|Layer menu command and in the Plot Details dialog box, for Layer 2, click on the Link Axes Scales tab and select the Straight (1 to 1) radio button for the X Axis Link and click OK.
At this point the top axis tick labels will be same as the bottom axis.

5. Make the worksheet active and add two columns. Enter the following data in those two columns:
Column(3):
4, 5, 6.6667, 10, 13.3333
Column(4):
0.25, 0.2, 0.15, 0.1, 0.075

Note that the relationship between these two columns is:
  col(4) = 1 / col(3)

Note further that col(4) has nicely rounded off numbers and col(3) does not.
So in this case the col(4) values can/need to be filled first and col(3) needs to be computed using the inverse of the nonlinear relationship function that is desired to be shown in the second axis.

6. Make the graph window active and then open the Script Window (menu command: Window|Script Window) and enter the following command and press Enter:
  layer2.x.ticksbydata$=

So, for example, if your workbook was named Book1 (for Origin 7.5 or older, the worksheet Data1 - likewise so forth on), and columns were A, B, C, D, you would enter
  layer2.x.ticksbydata$=book1_c
(Or, in Origin8 or later, you can use a range notation:
  range xticks = [book1]sheet1!col(3);
  layer2.x2.ticksbydata$=xticks;
)

7. Double-click on the top X axis tick labels and in the X axis dialog box, under the Tick Labels tab, change the Type drop-down to Tick Indexed Dataset, and the Dataset drop-down to Book1_D, which will point to column(4) that contains the nicely rounded labels that we wish to display.
Click on the Scale tab and enter 0 in the edit box for Minor Ticks.
Click OK to close the dialog.

Note that you can set up a similar relationship for a second Y axis. For the Y axis, under step 6, you will need to use the command:
layer2.y.ticksbydata$=


Schlüsselbegriffe: 
ID Number: 1116
Item Category: Curve Fitting
Origin Version: 8,7.5,7.0
Database Information Type: Tip
Number of Times Accessed: 11548
Creation Date: 01.05.2006 14:53:17
Geändert am: 05.06.2009 11:14:51

 

Copyright © 2012 OriginLab Corporation. All rights reserved.
20 Jahre Hochleistungssoftware für Wissenschaft und Ingenieurwesen