Contents |
Create PNG with sine plot:
gnuplot> set terminal png small gnuplot> set out 'somefile.png' gnuplot> plot sin(x)+sin(2*x)
Plot
set terminal png font "/usr/share/fonts/corefonts/arial.ttf" 12 size 800,600 #set terminal PDF output font-size 12 set out "test.png" set xlabel "x" set ylabel "y" set zlabel "sin(x)+sin(y)" set key below set nogrid set view 45,30,1.0 # view angles (rotation around x, rotation around y, zoom) set xrange [-3:3] set yrange [-3:3] set zrange [-2:2] splot "datafile.dat" with lines
Generate test data
-3.step(3, 0.1) do |x|
-3.step(3, 0.1) do |y|
z = Math.sin(x)+Math.sin(y)
puts "#{x} #{y} #{z}"
end
puts # groups points with same x values
end
The output data looks like this
-3.0 -3.0 -0.282240016119734 -3.0 -2.9 -0.38036933727385 -3.0 -2.8 -0.476108158215772 -3.0 -2.7 -0.568499888293697 -3.0 -2.6 -0.656621379881331
Create data file:
$ vim createdata.py
import math
d = 0
while d < 2 * math.pi:
print d,',',sin(d)+sin(2*d)
d += 2 * math.pi / 100
$ python createdata.py > datafile
The program outputs this:
0 , 0.0 0.0628318530718 , 0.00394264934276 0.125663706144 , 0.0157084194357 0.188495559215 , 0.0351117570559 0.251327412287 , 0.0618466599781
Create gnuplot program:
$ vim dataplot.gnuplot
set terminal png small
set out 'somefile.png'
plot 'datafile' using '%lf , %lf'
|_ plot the second column as a
function of the first