Wednesday, June 24, 2009

How to: create an "inset plot" or subplots with Grace?

Grace is an amazing data-analysis/plotting software that I use all the time, to create "journal" or "presentation" quality pictures.

Gnuplot is my workhorse, Grace is what I use when I want to play polo.

Although it is limited to 2D plotting, the professional quality of the product, the ability to export to a bunch of different formats (eps in particular), and the fact that it is freely available under GPL, make it irresistible.

Every once in a while, I have to make plots with insets. Like the one shown here. Each time I have to do it, I spend 15 minutes figuring out how to do it, 10 minutes to do it, and 5 minute telling myself how I should write it down for next time. So here are step-by-step instructions.
  1. Data -> Import -> ASCII to open the "Grace:Read Sets" dialog box.
  2. Read in data (here I read in three data sets), and clean up, as usual to create Graph 1, which is labeled G[0].
  3. To create Graph 2, open the "Grace:Read Sets" dialog box again.
  4. In the "Read to Graph" portion the "(+) G0" graph is selected by default.
  5. Right click on the "(+) G0" to open up a menu.
  6. Select "Create new"
  7. Read in data that you want in this graph, as in step 2.
  8. At this point everything looks muddled, since both the graphs are superimposed. Later on, you can use mouse to select the appropriate graph, but right now, since they are almost on top of each other we need a different strategy.
  9. Go to "Plot -> Graph Appearence -> Viewport".
  10. Adjust the min and max values until desirable.
  11. Now go on, as before. Remember to check which graph is "active" before making any changes.

Update: Consider using Veusz; it has a much more modern feel. I wrote about how to do inset plots with Veusz here.

26 comments:

  1. This was really useful to me. I had always wondered how you get the two graphs not to lie on top of each other without having to use plots next to each other. Thanks alot

    ReplyDelete
  2. Thank you for the post!

    I spent (without success) several hours on the Grace examples trying to figure out how to get such graphs, but with this tip took only a few minutes to get it!

    ReplyDelete
  3. Thanks for the very useful instructions!

    ReplyDelete
  4. Thanks for posting such a useful grace tips :)

    ReplyDelete
  5. Thanks a lot for the post. it is really very helpful...

    ReplyDelete
  6. hi
    i try to plot 2 graph in 1 same as yours . I follow the steps but I thing i am doing something wrong because when I want to see the second plot mine is emty my data is not included. I am stuck in this point.

    ReplyDelete
  7. HI,

    I can get untill step 8

    ReplyDelete
  8. thank you I sort it.

    ReplyDelete
  9. it is working if i put the same graph in 2 little graphs . what i do not do properly is when i have to put the data in the second graph.

    ReplyDelete
  10. Hi, as you seems to be an expert in Grace :-) and you tip also helped me. I was wondering if you know any way to using latex symbols in Grace plots?

    ReplyDelete
  11. Extremely useful! This is the first piece of documentation on xmgrace that I actually found helpful. Thank you so much!

    ReplyDelete
  12. Thank you very much: this was one of the two problems of my day =)

    maybe you know how to solve also the second one...I'll try to explain.

    I have a file with 3 column: A,B,C and I want to plot with grace x=A and y=B-C.

    Can I do it directly in grace without create the column D=B-C before?

    Thanks,
    Vale

    ReplyDelete
  13. Dear Vale, over the past year or so, I've started using a very nice plotting program called "Veusz" instead of Grace. It feels much more modern, is very easy to learn, and you can do the sort of dataset creation you ask about (subtract two columns) inside very easily.

    I think you'll be glad you made the switch.

    ReplyDelete
  14. Thanks sachin,
    I'll take a look ;)

    But when I know that a way exist for me it's impossible to change program and stop...I need to know how to use grace in such a way =D

    I think the way is "evaluateExpression". I plotted B vs A and C vs A. So now I have "only" to unserstand which set source and destination highlight (mumble mumble mumble)

    ReplyDelete
  15. uouh, I did it!!!
    You plot B vs A (S0 data set) and C vs A (S1 data set) then click on
    data --> transformations --> evaluateExpression

    As source set (on the left) select both S0 and S1 then in the space above put the formula
    y=s0.y-s1.y
    apply and on the plot now you have as third line the difference between the first two lines =)

    It was really a stupid problem!

    Thanks for your kind answer!
    Vale

    ReplyDelete
  16. Hi,
    I think I'm having the same problem as someone else did above. At Step 7, with G1 and my second xvg file highlighted I hit "ok" but the data loads into the G0 instead of G1.

    ReplyDelete
  17. Thanks this is useful.

    ReplyDelete
  18. Very useful and crisp. Thanks!

    ReplyDelete
  19. Thank you so much for sharing your knowledge, you are great!

    ReplyDelete
  20. Thanks a lot, this is very useful.

    ReplyDelete