# Some xmgrace tips

Xmgrace is a very nice piece of software to create publication quality figures. Even better is that it stores your data and graph layout options as plain text (which is especially nice in combination with subversion or scripts to edit your graph).

But some things are not very intuitive, which is why I keep a list of some useful possibilities below:

• Subscript, superscript
x-squared: x\S2\N
subscript: 3\s10\N
• Greek letters, example: theta
\f{Symbol}q\f{} or shorter: \xq\0q to get a theta symbol followed by the letter q: \x switches to the Symbol font and \0 switches back to Times-Roman.
• Special symbols, example: Angstrom symbol
\cE\C
For other characters, look at this list: ascii table with low and high characters. Just use the character from the left column between \c and \C to produce the one from the right column. I highlighted the most interesting characters (for a scientist). The \c and \C option are listed as deprecated in the xmgrace manual., but what is the new way?. The new method to insert special characters in xmgrace is:

• Press ctrl-e while positioned in a text-edit field to bring up the font dialog box.
• Select the desired font from the drop-down list. You probably want to use Symbol because it contains many of the commonly used special characters.
• Click on the character you want to insert
• Saving the default settings for new graphs:
open xmgrace, make the desired settings, save them as:
~/.grace/templates/Default.agr
Unfortunately, this does not save the "print" settings, but see below.
• Setting the default printer to print to .png files with 300dpi:
create the file ~/.grace/gracerc.user and enter the following text:
HARDCOPY DEVICE "PNG" DEVICE "PNG" DPI 300
• Changing the definition of the default colors:
Just edit the lines that say
@map color 7 to (220, 220, 220), "grey"
in the saved file. Edit the default file (see above) if you wish to use the new colors everywhere from now on.

If you have more helpful hints, please post them in the comments, so that this blog post will become an interesting collection of tips that can be turned into a useful "cheat sheet".

This entry was posted in linux, science. Bookmark the permalink.

### 55 Responses to Some xmgrace tips

1. louic says:

Some comments on this post were lost because of a harddisk crash at my previous hosting provider. My backup was not recent enough at the time of the crash to include those comments.
I changed to a different provider now and will re-post the comments if I manage to recover them.

2. Miles says:

Thanks for the excellent tips! I believe that the Default.agr tip doesn't work unless you put the file at the location ~/.grace/templates/Default.agr (or an equivalent sub-path of grace's search path).

3. louic says:

Thanks for your comment Miles, you are right and I changed it in the text.

4. Mac says:

Great tips!

I tried the save Default.agr tip, but I'm not allowed to save there under Ubuntu :(. Any ideas how to make that work?

5. louic says:

Hi Mac,

Did you try to save the file as ~/.grace/templates/Default.agr ?

Every user should have rights to save this file in his own home directory. It is possible that you need to create the directory first. If it already exists but you are not allowed to write there, only the administrator of your computer can solve that problem.

Good luck!

6. Mac says:

I am the administrator of my own computer, lol.

Thanks for the tips, I made a new directory .grace in my home and saved the file: and it works! Thank you so much :).

7. Dawit says:

I have a problem in xmgrace!! I want to use square roots to label my graph but I don’t know how to write it in the xmgrace. Please help me with this thing. Thanks!!!

8. louic says:

To make a square root symbol, use:
\f{Symbol}Ö\f{}

The new way to add symbols in xmgrace is:
press Ctrl-E while you are in the text field: this will bring up the font dialog box -> select the Symbol font -> click the square root.

Thanks for reminding me that this information was missing from my weblog, I will update the text.

9. Dawit says:

Thank you very much. Now, it works very well and I will have some questions in futures. Hopefully, you will assist me on this. Thanks again!!!

10. pc says:

hello, how do i write \tilde{\sigma} ? i have not yet been able to figure that out. please let me know.

11. louic says:

Do you mean you want to write a tilde symbol followed by a sigma symbol?
\f{Symbol}~s\f{}

12. Gilles says:

My old data sets used > as a set separator, which was accepted by xmgr.
The default set separator in Grace is &.
How can I make grace interpret > as a set separator?
Thanks

13. louic says:

I don't know how to do that, but why don't you just search and replace > by & in a text editor or with sed/perl/python or whatever tool you prefer?

14. Gilles says:

Yes, this is an option I considered.
I have many files and programs (such as GMT) using > as a
separator, so I thought there may be a simple way to do it in xmgrace. But editing the files is easy.
Thanks
G

15. abhijit says:

Thanks buddy :)

16. Snigdha says:

Hi Louic... Nice tips!!!
I have a question about set operation. I have two data sets and want to do make a 3rd data set which is average of these two. Is it possible to do it in xmgrace?

17. louic says:

Hi Snigdha,

It is indeed possible to take the average of two datasets in xmgrace, but not very straightforward imho. Here goes:

- Open the "Set Appearance" dialog box
- Right click on the list of sets, and choose "create new" -> "by forumla"
- For the x-axis, enter the starting point (= minimum value of x), ending point (= maximum value of x), and length (= number of data points). These values should of course correspond to the two sets you want to average.
- After "X =", enter $t (but is should already be there) - After "Y =", assuming you want to average the sets "s0" and "s1", enter (s0.y+s1.y)/2 - There you are! 18. Snigdha says: Thanks Louic... this was of great help... 19. Jefferson says: Thx for the tips! A question: do you also have problems with grace in newer versions of linux? I'm now using Kubuntu Natty and I just cannot any more select any text in grace (it's just not copied to the buffer or klipper). Googling for it I only find people with problems which seem related to fonts, no one else mentions the selecting/copying problem... 20. louic says: I have not had this problem with Grace-5.1.22 under Gentoo Linux (running Openbox 3), so I cannot help you with that. I hope someone else will be able to give you advice. 21. Ik had al bijna besloten om het gemiddelde van twee lijnen met een spreadsheet te maken toen ik me herinnerde dat Google m'n vriend is, en ik jou pagina vond. Hartelijk bedankt voor de tip. 22. vishal says: Hi thanks for nice tips here, can any one please help,Instead of average of two datasets in xmgrace, I have 1000 such data sets. Its not a good idea to type (s0.y ...s1000.y)/1000. Also I thought to copy paste by writing (s0.y ...s1000.y)/1000 through some script but -After "Y =" does not allow to paste :-( Is there any command method/or else by which I can do such thing in xmgrace?? thanks and regards; thanks and regards 23. louic says: Hi Vishal, The best advice I can give you is not to use xmgrace for this. It is a program for making nice plots, but not for doing calculations. Although it is possible, you will save yourself time and effort by using "the right tool for the right job". Personally, I would use Python and Numpy to do this, but if the datasets are not too large, a spreadsheet may be the easiest way. You may also want to have a look at qtiplot. 24. vishal says: I read here https://lists.phy.duke.edu/pipermail/phy246/2006/000029.html one has to write/print in bash or other terminal and then copy from terminal and finally paste in xmgrace. this is not working for number of lines.. regards; Vishal 25. vishal says: thanks louic!! 26. Bernard says: Thanks for this info -- I couldn't remember how to invoke specific fonts (like Courier-Bold). The "deprecation" of the old method of inserting symbols is very annoying to me. I generate many of my plots with batch (text) files, and any instructions that involve using mouse-cicks obviously can't be batched. Xmgrace gives lovely results, but it is the most incompletely documented package I've ever encountered. Perhaps I've been leading a very sheltered life. 27. Bernard says: BTW, I think user pc (from 26 July 2010) who wanted to do "\tilde{\sigma}" wanted to have the tilde *on top of* the sigma. This is a common enough operation in TeX/LaTeX, but (I assume) impossible with Grace. 28. louic says: @Bernard: I agree that xmgrace is not very well documented, and unfortunately not very intuitive (to me) either. I still use it though, it does indeed create nice plots. And I think you are right about the sigma. Thank you for your comments. 29. louic says: I have not tried it yet, but it seems to be possible to use LaTeX in xmgrace, see here: http://fisica.ufpr.br/fisux/post/tutorial/tutorial-002/ 30. natt says: thanks! very useful! 31. Jan says: Hi Louic, very nice tips! Maybe you also have an idea of how to adjust the size of the "Set Appearance" window? It does not fit in my screen so that its bottm is out of view and one cannot press the "apply" or "accept" buttons.. thx 32. louic says: Hi Jan, I don't think you can change the size of the window, but under Linux you can move any window with the mouse by holding down the Alt key. Just hold down Alt and click and drag anywhere on the window, maybe in that way you can work around the problem. 33. guest says: @Jan try free form: xmgrace -free 34. louic says: Thanks "guest", for your helpful comment. This indeed allows users to resize the xmgrace dialog windows. 35. Pritam Kumar Jana says: How to get the 'infinity' symbol in xmgrace? 36. just a chick says: Thanks for the tips, specially the one by luic. I installed the extra fonts and they work like a charm. -using mac where the fonts' location is: /Applications/Grace.app/Contents/Resources/grace/fonts/ For the person asking for a way to put ~ on top of sigma: it can be done in grace: \f{Symbol}s\S\h{-0.7}~ Grace has these commands \h and \v that shift the next font horizontally and vertically. It solves the problem (not very practical but..) 37. Jorge says: \f{Symbol} can be replaced by \x Jorge ;-) 38. louic says: Cheers Jorge. 39. xsong says: How can I change the editor from nano to vi in xmgrace on mac? Thanks. 40. louic says: The grace userguide (linked above) will tell you that you can set the environment variable GRACE_EDITOR. So in practice, if you are using Linux with a bash shell, type: export GRACE_EDITOR=nano xmgrace  41. xsong says: Thanks a lot, Louic. 42. Punam says: to fit the view into the window, type the following command from terminal: xmgrace -free filename 43. chicoree says: Hi, Thank you very much for your great tips. Regarding the default template question, is it possible to save also the Set Appearance and Axis Properties settings? I would like to make several plots with the same settings and it is quite tedious to do by hand (there are 60 such datasets!). I can't find how to do this with the Default.agr file. Thanks for your help! 44. louic says: Yes this is possible. Just save all the desired properties to Default.agr as described above and then plot your graph from a text file using, on the command line, something like xmgrace -nxy datafile.txt. The .agr files are simpy text files so you can edit them with a text editor and copy/paste the desired settings into each of the files. This can of course be automated with a search/replace function or a script. 45. louic says: Yes this is possible. Just save all the desired properties to Default.agr as described above and then plot your graph from a text file using, on the command line, something like xmgrace -nxy datafile.txt. The .agr files are simpy text files so you can edit them with a text editor and copy/paste the desired settings into each of the files. This can of course be automated with a search/replace function or a script. 46. Xandão says: VERY Nice post! Thanks! 47. Manish Paul says: I have rmsd, rmsf value in nanometer unit but I want to plot this value in angstrom unit. Is this is possible by Xmgrace? What is the steps? Any valuable suggestions are welcomed. Thanks in advance. 48. louic says: Hi Manish, Somewhere in the comments above I explain how to take the average of two datasets. You can use a similar method to muliply your values by 10, which will convert them from nanometre to angstrom. Have fun! 49. Manish Paul says: Thanks for your suggestion. But I need to know what is the exact formula I have to write there. I have mentioned start point, stop point and length. I have wrote$t in X set and \$t*10 at Y set. After applying and accepting the changed parameter, the graph remain unchanged i.e. the unit of Y axis does not change to angstrom. So, I want to know what the mistake I have made. Please correct me with the exact formula.