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

See also the Grace users guide and the grace forums.

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

  4. 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!

  5. 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 :).

  6. 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!!!

  7. To make a square root symbol, use:

    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.

  8. 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!!!

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

  10. 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?

  11. 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?

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

  13. 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?

  14. 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!

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

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

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

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

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

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

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

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

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

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

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

    For the person asking for a way to put ~ on top of sigma: it can be done in grace:
    Grace has these commands \h and \v that shift the next font horizontally and vertically. It solves the problem (not very practical but..)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>