Gnuplot

Notes on Gnuplot

Plotting

using the file toy1.ascii, and the gnuplot script plot.p I made the following images with gnuplot. You would make these same plots by starting gnuplot in a terminal, then typing at the prompt:

Be sure that you've downloaded the file and the script into the directory that you are running gnuplot from.

gnuplot> load "plot.p"

Brief explanation of what the script is doing…

set title "Title of Plot"
set autoscale

set xlabel "X-Axis Label"
set ylabel "Y-Axis Label"

The top of the code sets the Title that will show up on each successive plot.
Setting autoscale has gnuplot determine what the x and y ranges should be (to tell it specifics: set xrange [4000:4002], etc.)

Setting the x and y axis labels

p"toy1.ascii"us 2:3w l

Notice that there are shortcuts being used, this command in full form is:

plot "toy1.ascii" using 2:3 with lines

And is telling gnuplot to plot the file toy1.ascii, using column 2 as the x values, and column 3 as the y values, and connect the points with a line

toy1.gif

p"toy1.ascii"i 0us 2:3w l

(You can comment a line out of a gnuplot script with a hash "#" (gnuplot doesn't do anything with the line))

# previous line in expanded form
#plot "toy1.ascii" index 0 using 2:3 with lines

The only thing different here is the use of an "index" — notice in the toy1.ascii file that there are 2 blank lines that break the data up. This signifies an index break, and gnuplot starts counting with 0.

Gnuplot will interpret a single blank line as a "lift the pen" command.

toy2.gif

p"toy1.ascii"i 0us 2:3w l,""i 1us 2:3w l
#plot "toy1.ascii" index 0 using 2:3 with lines,"" index 1 using 2:3 with lines

There are two things different here. First you are plotting 2 things now: after the comma, gnuplot plots the next thing in the line. If I had a different file name with data I wanted to plot on top, I would have put that file name in quotes, but since I'm using the same file, I can just put empty "" to tell it "we are in the same file".

toy3.gif

p"toy1.ascii"i 1us 2:3w l,""i 1us 2:4w l

#plot "toy1.ascii" index 1 using 2:3 with lines,""index 1 using 2:4 with lines

toy4.gif

p"toy1.ascii"i 1us 2:($3/$6)w l,""i 1us 2:($4/$6)w l

toy5.gif

p"toy1.ascii"i 1us 2:($3/$6)w l ti"Normalized Flux Data",""i 1us 2:($4/$6)w l ti"Errors"

#plot "toy1.ascii" index 1 using 2:($3/$6) with lines title "Normalized Flux Data","" index 1 using 2:($4/$6) with lines title "Errors"

toy6.gif

To do a few things that are a bit trickier…

to plot 2 files' columns:

plot "< paste noI2full67.ascii I2full67.ascii" using 2:($3/$6-$9/$12) with lines

plotting data separated by 2 white lines

plot "file.ascii" index 0 using 1:2 with lines

plotting data with asymmetric errorbars:

p"ryan.ascii"using 1:2:($2+$3):($2-$4) w yerrorbars

Multiplot Multiple plots

set term gif

Terminal type set to 'gif'
Options are 'nocrop medium '

set output "chad.gif"
set multiplot layout 2,1
p"noI2_67.ascii"w l
p"alliodinenorm.ascii"us 1:(-$2+1) w l
unset multiplot
set term x11

Set Commands

set xrange [min:max] or 'restore'
set autoscale x
set terminal

this will give you options

set term gif
set output "filename.gif"
plot "thing you want to plot"

Prints out the graph to a gif file (jpeg,etc. works the same way).

plot "noI2full67.ascii" using 2:($3/$6) with lines

To print the 2nd column of data against the third divided by the 6th column of data (with lines of course).

set label 1 "HeI 515.616500"at 1706.221000,25 rotate
set arrow 1 from 1706.221000,0 to 1706.221000,1000 nohead linetype 3

Setting vertical lines with labels

set arrow 35 from 5321.995300,0.1 to 5321.995300,1 nohead linetype 0 lw 1

Setting a dotted vertical line, linewidth 1.

set term postscript (color —optional)
set output "noI2_G46.ps"
set yrange[0:1000]
plot "noI2_PHL957_G46.ascii" with lines
set output "noI2_G47.ps"
plot "noI2_PHL957_G47.ascii" with lines
set output "noI2_G48.ps"

Fitting

w3(x) = a3*x*x+b3*x+c3
fit w3(x) 'cleanchi3.ascii' using 1:2 via a3,b3,c3
replot

(1)
\begin{equation} y = a x^2+b x +c \end{equation}
(2)
\begin{equation} 0= 2 a x + b \end{equation}
(3)
\begin{align} x = \frac{-b}{2 a} \end{align}

If you want the parameters to have errors that you can call later on:

set fit errorvariables

and now the variable a23 will have error that the prog will call a23_err.

Output plot to file

set table "output.file"
plot "noI2_PHL957_B.ascii" using 2:($3/$6) with lines

Output print to a file

set print "output.file"
print 34, 23

to restore:

set print

Misc. Notes to be filed later

To see how the convolution ranges fit vs. the difference between the lines:

set xrange [5327:5328]
p "smoothconv.ascii" using 1:2, "smoothkdif.ascii" with lines

Spline things

plot "filename" index 5 smooth cspline (cubic spline), "" (use same file) index 5 with points

gnuplot> p"sigmabin_67.5.ascii"i 5 smooth csplines,""i 5 w points

This one sets the output, sets multiplot (2 rows, 1 column),
The first graph:
title over the first one, plot "marcy" index 3 using 1 and -2nd column +1.75, with lines, title the line in the legend "Convolved Iodine" AND an overplot on this same graph.
setting no title
plotting 2nd graph
unsetting multiplot (needed to output the gif). (see writeup for masses)

set output "gif103.gif"
set multiplot layout 2,1
set title "Subtracted Keck Lines and convolved Iodine lines shifted: 0.020750"
p"marcy_convolved_67.ascii"i 3 us 1:(-$2+1.75) w l ti "Convolved Iodine","observed_noI2_minus_I2_67.ascii"us 1:(-$2+1.75) w l
unset title
p"alliodinenorm.ascii"us ($1+0.02+0.000750):2 w l
unset multiplot
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.