next up previous contents index
Next: 5.2 Error Bars Up: 5 Plotting with IFEFFIT Previous: 5 Plotting with IFEFFIT


5.1 Specifying Data for Plotting

The plot() command plots arrays of data. Typically, you you will specify array names for both the x- and y-arrays, as in

  Ifeffit> plot(x= my.x, y= my.y)
Of course there are many other optional keywords you can give to plot(), but here we're just focusing on the x and y arguments because they are the most important. As you use IFEFFIT, you'll find that a simple plot() command such as the one above gets used a lot. Because of this, even this simple plot() command can be made easier, more flexible, and more powerful, as will be discussed here.

First, the plot() command uses the concept of positional keywords, so that you can drop the x= and y=, and just use

  Ifeffit> plot(my.x,my.y)
that is, the first argument in the list (i.e., everything between '(' and the the first comma) without an explicit keyword is assumed to be the value for x, and the second argument without a keyword is assumed to be the value for y. Since a command that fits on a single line can drop the parentheses, this can become
  Ifeffit> plot my.x, my.y

Much, or perhaps most, of the data you'll want to plot will be in a single group. If the x and y arrays you intend to plot are in the same group, you can specify the group once, and only give the suffixes of the array names:

  Ifeffit> plot x, y, group=my
In fact, if the string variable $group is set to the group you want (and it often is set to the ``current group'' after most data processing commands, and the plot() command itself), this group name will be used by default:
  Ifeffit> $group = my
  Ifeffit> plot x, y
  Ifeffit> plot x, z
which greatly simplifies the task of over-plotting data from the same group.

Since there are two plot() commands in the above example, this is a good time to discuss when the plot window gets cleared for a fresh plot. Normally, the plot() command adds the specified trace to the existing plot: over-plotting is the normal behavior. To clear the plot, you can use

  Ifeffit> newplot (my.x, my.z)
which will erase the previous plot and start over. You can simply send an empty newplot() command and subsequent plot() commands will add to this refreshed plot window.

In many cases, you'll want to plot more than one y array as a function of the same x array. This leads to a slight variation on the rule for positional keywords. I said above that the first argument without a keyword is taken for x and the second for y, but the full truth is a little more complicated. If exactly one argument has no keyword, and there is no explicitly set y=... argument, then the argument without a keyword is actually taken as the <TT>y array. In this case, the x array is the previous x array. That is, after

  Ifeffit> newplot (my.energy, my.xmu)
these two commands will produce the same effect:
  Ifeffit> plot my.energy, my.bkg
  Ifeffit> plot bkg
If you give only one array for the first trace to plot, a simple index array (i.e, 1,2,3,4,...) will be used for x, so that
  Ifeffit> newplot my.energy
would be equivalent to
  Ifeffit> my.tmpx = indarr( npts(my.energy))
  Ifeffit> newplot my.tmpx, my.energy

That covers how to make the plot() command simpler, now let's look at how to make it more complicated. As the last example hints at, sometimes it's desirable to plot arrays that do not yet exist as named arrays in IFEFFIT. For example, to view $ \chi$(E) = $ \mu$(E) - $ \mu_{0}^{}$(E) after a background subtraction from spline(), you might say

  Ifeffit> cu.chie = cu.xmu - cu.bkg
  Ifeffit> plot(x= cu.energy, y= cu.chie)
or use one of the simplified forms discussed above. But if you only want to view $ \chi$(E), not do any processing with it, it seems unnecessary to create it. So, in fact you can pass a simple expression as the y (or x) argument to plot():
  Ifeffit> plot(x= cu.energy, y=cu.xmu-cu.bkg)
In fact, the expression can include any of the data and any of the functions described in section 3.5. This provides a flexible way to plot a variety of functions, but there are some caveats to using expressions instead of existing arrays. First, to be sure the expression is parsed correctly, you should put it in quotes:
  Ifeffit> plot(cu.energy, y="(cu.xmu - cu.bkg)*(cu.energy-e0)")
This is especially true if the value in the keyword/value pair contains spaces: use quotes or you're likely to get several warnings and weird results. Also, when using an expression instead of an existing array, you should not rely on x and y being default positional keywords, and explicitly use the y= as shown above.


next up previous contents index
Next: 5.2 Error Bars Up: 5 Plotting with IFEFFIT Previous: 5 Plotting with IFEFFIT
Matt Newville
2004-02-09