ZoneO-tips for Mandriva Linux

Scientific Plots with Mandriva Linux

How do plot scientific charts with Mandriva?


1- Software and basic considerations

Well, that's a tough one! There are numerous types of scientific plots, with an infinite number of styles and features... So, I'll try to keep it simple and show you the basics. Just remember that there are many other possibilities...

In terms of software, there are quite a few choices, but I'll cite only two of them:

  • Gnuplot: a command-line driven interactive data and function plotting utility,
  • Grace: WYSIWYG 2D plotting tool for the X Window System and M*tif.

Both of them are free and available for a variety of platforms, including mandriva linux (see the previous tutorial "Install new software with Mandriva"), and even windows... Gnuplot has probably more features such as 3-D plots, good color handling, and tons of customization. On the other hand, it's command line driven, it can take time to learn, and it remains hard to use. Grace includes a nice graphical user interface, powerful mathematics, and is definitely easier. It all depends on what you want to do, but for a simple and quick 2-D chart, I find that using grace is more convenient...

2- Plotting a 2-D dataset

Start grace
Figure 1: Start grace
Import ASCII file with grace
Figure 2: Import ASCII file with grace
A plot
Figure 3: A plot

Now, let's say you want to plot a simple 2-D dataset out of a file with a number columns of data. Your data will have to be stored in a simple text file, space or tab separated, and using the # symbol for comments. For instance, we'll use something just a scientific as the Yahoo stock price for 2005 (source: This file has 7 columns, first one is the date, and last one is the actual quotation for the day.

There are issues with importing dates in grace, but this file will work if you set it to use the European standard (in the preferences).

To import the data, select the menu Data -> Import -> ASCII... and you'll have the window described in Figure 2:

  • select the proper directory,
  • make sure that the filter will not hide your file (replace *.dat with *.csv for instance),
  • select your file,
  • select the option Load as "Block data",
  • click Accept
In the second panel,
  • select XY plot,
  • X from column 1,
  • Y from column 7,
  • and click Accept.

That's it, you've done a 2-D plot (Figure 3).

3- Customize the plot

A plot
Figure 4: changing axis properties
A plot
Figure 5: a plot, after adjusting axis properties, set appearance, and the legend

Fair enough, you have a plot, but it doesn't look great! There are tons of ways to customise the plot, but here are the main ones...

Background: by default, the background is solid white, you can change in Plot -> Plot appearance. There are a few choices for color, or you can choose to remove the Fill option (no background). This last choice (no background) is highly recommended if you will export your plot in PS or EPS.

Plot size, frame, or title: the can be set in Plot -> Graph appearance. For instance, you can make it slightly smaller, with a thicker frame (Figure 5).

Axis: axis properties (scale, ticks, fonts, labels) are changed in Plot -> Axis properties (Figure 4).

Line and symbols: line colors, symbols, error bars, and all those things are in Plot -> Set appearance.

Legend: adding a legend takes a few steps. First of all, you have to give a name to each dataset in Plot -> Set appearance. Then, the legend properties (font, frame, background, or location) are in the Leg. box and Legends tabs, in the graph appearance dialog (menu Plot -> Graph appearance).

All in all, it's not too difficult, and with a bit of work, you should get something like Figure 5.

4- Basic math, statistics, and curve fitting

A plot
Figure 6: calculating running averages
Non linear curve fitting with grace
Figure 7: non linear curve fitting with grace
Yahoo stock prices in 2006
Figure 8: ZoneO's analysts prediction for Yahoo stock price in 2006!

Now that you have a decent plot, you may want to perform some data processing, and grace is actually pretty good at it. Here, I'll give you a few examples, but do not hesitate to explore the different menus, the grace documentation and other pages around the web to find out more!

Running averages are built in. Just select the menu Data -> Transformations -> Running averages, select the dataset to use a source, the length of the average, change a few colors in Plot -> Set appearance, and you'll get a plot like figure Figure 6

Curve fitting (basic): to fit a polynomial, power law, exponential, or log curve to your data, you should use the functions available under Data -> Transformations -> Regression. Select the set to fit, the curve to adjust, and what to plot. Load Fitted Values is usefull if you already have a lot of points. If you have few points and want to use the fit to interpolate, you should use the option Load Function with a proper interval and number of points.

Curve fitting (advanced). If the function you want to fit is not available, you should make use of Data -> Transformations -> Non Linear Curve Fitting.... For instance, our Yahoo stock prices for 2005 look a lot like the sum of a straight line and a sine curve with a period of about 180 days, an equation like

y = a0 + a1x + a2 * sin(x*2*pi/a4-a3)
with a starting value of 180 for a4. Well, you can just enter this equation with the proper starting value for a4 and you should get a decent fit (Figure 6). If you want your fit to extend further than the data, simply go into the Advanced tab, and instead of loading the Fitted values, load the Function with a proper interval and number of points.

And here you go with the ZoneO prediction for the Yahoo stock price in 2006, in Figure 8. And let me tell you, it's as good as it gets!!

5- Export for further use

Final image
Figure 9: the final plot, exported in PNG.

Before you publish your plot, you'll have to export it... In grace, you can choose the format for exporting through the File -> Print setup... menu. You have a choice between

  • postscript and encapsulated postscript (EPS),
  • framemaker (MIF),
  • scalable vector graphics (SVG),
  • PNM,
  • jpeg,
  • and png.
Also, remember to set the file name in the Print setup dialog! Once you selected your format, simply select File -> Print and your plot will be exported. Personnally, I mainly stick with EPS for files that will be included with scientific documents (e.g. in LateX), eventually converted to PDF using the command epstopdf, and JPG or PNG, eventually edited in the GIMP, for other uses.

Finally, I offer you my predictions for Yahoo stock prices in 2006, in PNG format, in Figure 9. Enjoy!


Updated: 03/2006
© ZoneO-soft - Contact us - Start page