You are on page 1of 2

GnuPlot Tutorial

1. Type gnuplot at the unix terminal, it will open an interactive session.


2. We will start by making some simple plots at the command line
1. Type plot 4 and hit enter. View the resulting graph.
2. Type plot x and hit enter.
3. Type plot 4,x and hit enter. You should see both of these lines in the same figure now.
3. Now we will change up the axis labels
1. With your previous figure still open, go back to the gnuplot command line.
2. Type set xlabel 'X-axis' and hit return. You should see that nothing comes up yet on the
graph. Now type replot and hit enter. Now change the y axis label by typing set ylabel 'Y-
axis'. Of course, you can make these labels whatever you want.
4. We will label plots now.
1. Type plot sin(x) title 'Sine Function' and hit enter.
(1) You should see 'Sine Function' appear somewhere on the graph of the sine function. You
probably also see 'Y-axis' and 'X-axis' on the figure. Let's remove those by typing set
xlabel ''; set ylabel ''; replot and hitting enter.
5. Other formatting options
1. Let's start with a new graph. Type plot x**3 – 3*x**2 + 4*x – 2 title 'My Graph', x**3 +
3*x**2 – 4*x + 2 title 'My Other Graph'
2. Type set xrange [-20:20]; set yrange [-10000:10000]; replot
3. Type set key -5,8000; replot
4. Type set xlabel 'X-axis'; set ylabel 'Y-axis'; set title 'My Graph'; replot
6. Now we will see how to load data from a data file into gnuplot, and to load the commands we
want to use for plotting from a script instead of from the interactive command line.
1. Start a new gnuplot session. Type exit and hit enter. Then type gnuplot to start gnuplot up
again.
2. Make sure that gnuplot_data.dat and gnuplot_plot_script.p are in the same directory. Type
load 'gnuplot_plot_script.p' at the prompt and hit enter.
3. You should see a figure with three curves come up. The commands in the
gnuplot_plot_script.p file issued the commands necessary to make this figure, using data in
the gnuplot_data.dat file. Take a look at these files in another terminal window using nedit
or vi.
7. We will finish by saving figures.
1. Type set terminal postscript and hit enter
2. Type set output 'graph.ps' and hit enter
3. Type replot and hit enter
4. Type set terminal png and hit enter
5. Type set output 'graph.png' and hit enter
6. Type replot and hit enter
7. Now type exit and hit enter to exit gnuplot.
8. Type ls at the unix prompt and you should see the files graph.ps and graph.png
9. Type gimp & and open the figures to look at them.
XMGrace Tutorial

1. Type xmgrace & at the unix prompt.


1. You should see a screen pop up with lots of menus and an empty graph.
2. Go to Data, Import, Ascii
3. Under Load as, choose Block Data
1. If you had a data set with only two columns, this step would not be necessary. But our data
has multiple columns in it, so we need to load as 'Block Data' so that we can tell XMGrace
which columns we want it to plot.
4. Double click on the data file in the window, and then another window will open asking you to
Edit block data. For X from column choose 1, and for Y from column choose 3, then click
Apply. Now change Y from column to 4 and click Apply, and finally change Y from column
to 5 and click Apply. Then close the Edit block data window, and the Data Import windows.
5. You should have three lines, a black, red and green line. Xmgrace will cycle through colors in a
specific order as you add lines.
6. Double click on the x-axis and an axis editing window should come up. It should be fairly self-
explanatory, so play with the various options in here and try changing x-limits and axis labels,
or tick spacings. You'll have to hit Apply to see the changes type effect. You can also edit the
y-axis from this menu by changing from x to y at the top. Go through the various tabs and see
what options you have as well.
7. Go to Plot menu and then Graph Appearance. You can add a graph Title and Subtitle here,
and with the other tabs do things like change where the Legend box will be for the various
curves.
8. Go to Plot menu and then Set Appearance to change things about the data sets. You can
change line styles, line colors, etc using these menus. So play with these and see what you can
do with your figure.
9. Finally we'll save our session and print a figure. '
1. Go to File menu and then Save as
2. At the bottom in the Selection box go to the end of the line and type grace_figure.agr and
then click OK to save.
1. This is a grace file, and if you open it later in another session of xmgrace it will load
back in all the stuff you have done so you can continue working on your graph.
2. Now go to File and Print setup. For Device leave it as Postscript. In the File name
box it should be the name of the xmgrace file then .ps, you can change it to whatever
you want though. Click Apply.
3. Go to the File menu and then to Print
4. Now go to your unix terminal and type ls, and you should see your file printed to a ps
file. Type gimp & and then open the file to look at it.
10. You can do lots of stuff with XMGrace, this is the plotting software I prefer, so it is worth your
time to get to know the ins and outs of this software.

You might also like