# 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".

## 39 thoughts on “Some xmgrace tips”

1. 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. 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. 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. 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. 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. 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. 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. 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. 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:

thanks louic!!

25. 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.

26. 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.

27. @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.

28. natt says:

thanks! very useful!

29. 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

30. 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.

31. guest says:

@Jan
try free form:
xmgrace -free

32. Thanks "guest", for your helpful comment. This indeed allows users to resize the xmgrace dialog windows.

33. Pritam Kumar Jana says:

How to get the 'infinity' symbol in xmgrace?

34. 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..)

35. \f{Symbol} can be replaced by \x

Jorge ;-)

36. Cheers Jorge.