Tuesday, March 11, 2008

Tryst with Xmgrace

Xmgrace is a great WYSIWYG 2D plotting software available with GNU/Linux. Unfortunately it does not support 3D plotting at the moment. If you want to produce good quality graphs for technical papers, you should try your hands at it.

Typesetting

Grace permits quite complex typesetting on a per string basis. Any string displayed (titles, legends, tick marks,...) may contain special control codes to display subscripts, change fonts within the string etc.


Example:

F\sX\N(\xe\f{}) = sin(\xe\f{})\#{b7}e\S-X\N\#{b7}cos(\xe\f{})

prints roughly

                       -x
F (e) = sin(e)·e ·cos(e)
x

using string's initial font and e prints as epsilon from the Symbol font.

NOTE: Characters from the upper half of the char table can be entered directly from the keyboard, using appropriate xmodmap(1) settings, or with the help of the font tool ("Window/Font tool").


Control code
Description
\f{x} switch to font named "x", e.g. \f{Times}
\f{n} switch to font number n
\f{} return to original font
\R{x} switch to color named "x"
\R{n} switch to color number n
\R{} return to original color
\#{x} treat "x" (must be of even length) as list of hexadecimal char codes
\t{xx xy yx yy} apply transformation matrix
\t{} reset transformation matrix
\z{x} zoom x times
\z{} return to original zoom
\r{x} rotate by x degrees
\l{x} slant by factor x
\v{x} shift vertically by x
\v{} return to unshifted baseline
\V{x} shift baseline by x
\V{} reset baseline
\h{x} horizontal shift by x
\n new line
\u begin underline
\U stop underline
\o begin overline
\O stop overline
\Fk enable kerning
\FK disable kerning
\Fl enable ligatures
\FL disable ligatures
\m{n} mark current position as n
\M{n} return to saved position n
\dl LtoR substring direction
\dr RtoL substring direction
\dL LtoR text advancing
\dR RtoL text advancing
\x switch to Symbol font (same as \f{Symbol})
\+ increase size (same as \z{1.19} ; 1.19 = sqrt(sqrt(2)))
\- decrease size (same as \z{0.84} ; 0.84 = 1/sqrt(sqrt(2)))
\s begin subscripting (same as \v{-0.4}\z{0.71})
\S begin superscripting (same as \v{0.6}\z{0.71})
\T{xx xy yx yy} same as \t{}\t{xx xy yx yy}
\Z{x} absolute zoom x times (same as \z{}\z{x})
\q make font oblique (same as \l{0.25})
\Q undo oblique (same as \l{-0.25})
\N return to normal style (same as \v{}\t{})
\\ print \
\n switch to font number n (0-9) (deprecated)
\c begin using upper 128 characters of set (deprecated)
\C stop using upper 128 characters of set (deprecated)

Putting Symbols into Axis labels:

If you need special characters or special formatting in your label, you can use grace escape sequences (the sequence will appear verbatim in the text field but will be rendered on the graph), see typesetting above. If you don't remember the mapping between alphabetic characters and the glyph you need in some specific fonts (mainly symbol and zapfdingbats), you can invoke the font tool from the text field by hitting CTRL-e. You can change fonts and select characters from there, they will be copied back in the text field when you press the "Accept" button. Beware of the position of the cursor as you enter text or change font in the font tool, the character or command will be inserted at this position, not at the end of the string!


Note that you should see \f{Symbol} in the Cstring field of font tool when you select a symbol. In case you don't, write down manually and then click on a symbol you wish to insert and then press 'Accept'.

overlaying graphs

  1. Begin by selecting Main:Edit/Overlay graphs to bring up the Overlay widget.
  2. Select the graph numbers with which we would like to deal. In this example, we will overlay graph 1 onto graph 0. At this point, only graph 0 is visible. We cannot see Graph 1 to select since it does not exist at this point. We need to create simply by pressing mouse button 3 in a graph list window and selecting create new.
  3. The overlay type is determined by what is common among the overlayed graphs. In our example, the x axis is common so we will select X-axes same, Y-axes different. This is important because we don't want to alter any axes of the Overlay graph which we set the same as the underlay graph. In this example, we don't want to alter the x-axis of graph 1.
  4. We are now ready to label the graph axes and read the data. One thing we must be careful to do is to always make sure that we are working on the intended graph. Seeing as the graphs are overlain, clicking within the frame is ambiguous as to what graph is selected. The rule is that in a region of overlay, clicking will cycle between the graphs. Hence, if graph 1 is selecting, clicking within the frame will toggle to graph 0.
  5. Making sure that graph 0 is active, bring up the Axis properties widget. Now set the y axis title to Gnus.
  6. Select graph 1 as active as set the title as Gnats. Notice how it overlaps the Gnus. We want to put this on the right side. From the axis label and bar tab, select label Properties/Side=Opposite.
  7. Label the x axis to label it. If graph 1 is the current graph, noticed how it is greyed out because only 1 x axis need be active. Select graph 0 and you should now be able to alter the axis label.
  8. You are ready to read in data. Just make sure the graph that is active when you read in the data (or create your set) is the one in which you intend it to go.

9 comments:

Swagat said...

this is how you would write \dot{x} = 4

x\h{-0.4}\v{0.7}.\v{}\h{} = 4

Vins said...

Hey
Is there any other way to or any other plotting software in which the labeling and typesetting will be easier?
Your example helped me to type 1-r/r0 using the command line
1 - \v{0.7}r\v{}\h{-0.4}-\h{-0.3}\v{-0.7}r\s0

Don't you think using latex typesetting like
1-frac{r}{r_0}
will make your life much more easier. But unfortunately xmgrace lacks this I feel.
Is there any other plotting package able to do latex integration?

Unknown said...

Hi!
Is there any way to write a tilde over a letter, like the Favre Averaging?
In LateX, in will be : tilde{U}

Any help, please?

Unknown said...

You can insert arbitrary latex typesetting (equations, special symbols, all the fonts, etc.) into Grace plots using PSfrag:

In your xmgrace plot, insert text that you want to replace with latex. Print to an EPS file as usual when embedding figures in latex documents.

In your latex doc, include these two packages in the preamble:
\usepackage{graphics,psfrag}
\usepackage{graphicx,psfrag}

and text such as:
\begin{figure}
\psfrag{text to replace here}[b][b][1.2]{$latexed equation here$}
{
\includegraphics[width=0.90\textwidth,clip=true]{path to file/filename here}
}
\caption{}
\label{fig}
\end{figure}

You can add lots of text, equations, etc. to Grace plots this way.

Bahram Houchmandzadeh said...

I use a mixt of xmgrace and inkscape : I export the xmgrace into svg format, import the svg into inkscape and then add whatever I want (decoration figures, latex equations, ...).

dave said...

Hey!

Would you please help me how to write pbar?

Thanks

dave said...

Sorry again!

Would you please help me how to write pbar or any letter with bar in xmgrace?

Thanks

Some guy said...

Thankyou! That ctrl-e bit saved me a lot of time. Time enough to write a nice comment here.

Vale said...

Hi!
How can I write in the label a derivative? in latex I write \dot{G(t)}...

Could you help me?
Vale
vlgpan@gmail.com