Friday, June 1, 2012

Grace Tutorial: How to plot a graph with two different y-axes?

Say you have a dataset that looks like

x1, y1, Y2
x2, y2, Y2
...
xn, yn, Yn

and you want to plot (x,y) and (x,Y) with the same x-axis but different y-axes. As an example, consider the following graph (bigger versions of graphs upon clicking) where (x,y) are on a linear scale, and (x,Y) are on a logarithmic scale.


How do you make such a picture in Grace?

The strategy is very similar to making inset plots, which I wrote about a while ago. In fact, we could use essentially the same method, where the "inset" is the size of the main graph.

But we can do slightly better (and not have to deal with manually cleaning up extra tics) by using the "overlay" feature.

1. Read in the (x,y) dataset into the default graph G0 using Data -> Import -> ASCII dialog box.
2. In the same dialog box (Grace:Read Sets), right click on the "G0" graph, and choose "Create new" and create a new graph "G1"


3. Read in the other dataset (x,Y) into this graph. At this point, the graph looks somewhat garbled as seen below.


4. Click the Edit -> Overlay graphs to open up the overlay dialog box which looks like the following picture. I chose to overlay G1 on G0, and use a common x-axis. You can make different choices.


5. Once you do that, you essentially get what you need. You can go ahead and edit the appearance of the axes and sets. Since the graphs are on top of each other, it is sometimes hard to figure out which graph you are changing. Remember that clicking on the screen lets you toggle through the graphs. If you have widely varying y-axis (as in this example) you can figure out which one is active by looking at the co-ordinate marker right below main menu on the top left side.

6. Alternatively, you can open the Plot -> Graph appearance dialog box and changes the co-ordinates of the viewport so that the two graphs are non-overlapping. It makes clicking easier. You will have to repeat step 4, and undo changes to the viewport, once you've modified the graphs to your satisfaction.







12 comments:

Rohan Mishra said...

Thanks for posting this!

cbse class 8 sample papers said...

The graphical representation in math is the best option to understand the problem or to solve the problem like linear equations solutions,limit and calculus,functions all are solved with the help of mathematics.

SB said...

thanks for the post. do you have any idea how to plot a graph with two different scales in one axis? say along x axis, if I want to use a scale upto x1, and beyond x1 another scale. Is it possible?

Anonymous said...

Thnx m8

Anonymous said...

Great post. It's very helpful. Thanks a lot.

Anonymous said...

This is exactly what was I looking for. Thank you very much.

Anonymous said...

Very helpful

Unknown said...

I am failed to overlay following dataset please help me.
@with g0
@ xaxis label "Distance (Ang)"
@ yaxis label ""
@ legend 0.2, 0.995
@ legend char size 0.60
@ s0 legend "Int[:4&!@C,O,CA,HA,N,H]"
@target G0.S0
@type xy
0.250 0.000000
0.750 0.000000
1.250 0.000000
1.750 0.000000
2.250 0.000000
2.750 0.000000
3.250 1.200000
3.750 2.000000
4.250 2.400000
4.750 5.100000
5.250 8.700000
5.750 13.500000
6.250 18.900000
6.750 24.900000
7.250 31.700000
7.750 40.400000
8.250 50.500000
8.750 64.100000
9.250 79.600000
9.750 98.500000
@ s1 legend "Raw[:WAT@O => :4&!@C,O,CA,HA,N,H]"
@target G0.S1
@type xy
0.250 0.000000
0.750 0.000000
1.250 0.000000
1.750 0.000000
2.250 0.000000
2.750 0.000000
3.250 12.000000
3.750 8.000000
4.250 4.000000
4.750 27.000000
5.250 36.000000
5.750 48.000000
6.250 54.000000
6.750 60.000000
7.250 68.000000
7.750 87.000000
8.250 101.000000
8.750 136.000000
9.250 155.000000
9.750 189.000000

Unknown said...

I am failed to overlay following dataset please help me.
@with g0
@ xaxis label "Distance (Ang)"
@ yaxis label ""
@ legend 0.2, 0.995
@ legend char size 0.60
@ s0 legend "Int[:4&!@C,O,CA,HA,N,H]"
@target G0.S0
@type xy
0.250 0.000000
0.750 0.000000
1.250 0.000000
1.750 0.000000
2.250 0.000000
2.750 0.000000
3.250 1.200000
3.750 2.000000
4.250 2.400000
4.750 5.100000
5.250 8.700000
5.750 13.500000
6.250 18.900000
6.750 24.900000
7.250 31.700000
7.750 40.400000
8.250 50.500000
8.750 64.100000
9.250 79.600000
9.750 98.500000
@ s1 legend "Raw[:WAT@O => :4&!@C,O,CA,HA,N,H]"
@target G0.S1
@type xy
0.250 0.000000
0.750 0.000000
1.250 0.000000
1.750 0.000000
2.250 0.000000
2.750 0.000000
3.250 12.000000
3.750 8.000000
4.250 4.000000
4.750 27.000000
5.250 36.000000
5.750 48.000000
6.250 54.000000
6.750 60.000000
7.250 68.000000
7.750 87.000000
8.250 101.000000
8.750 136.000000
9.250 155.000000
9.750 189.000000

Anonymous said...

Can somebody please tell me how to do a dot product on XMGRACE. for example I did y0=x.y
but it did not work!

Thanks in advance for your help!
Regards,
JJ

Nimish Dwarakanath said...

It was very helpful. Thank you

hana kerdegari said...

I have a question. How I can have the first picture in this post? Two graph with two different y axis ? One y axis in the left side and the other one in the right side!