Skip to main content Svelte Highlight v7.23.1

Gnuplot language preview

1. Plotting a function

a classic sine/cosine comparison with labeled axes
horizon-dark
set terminal pngcairo size 800,600
set output 'waves.png'
set title "Sine and Cosine"
set xlabel "x"
set ylabel "f(x)"
set grid
set xrange [-pi:pi]
set key top right

plot sin(x) title "sin(x)" with lines lw 2, \
     cos(x) title "cos(x)" with lines lw 2 dashtype 2
atom-one-dark
set terminal pngcairo size 800,600
set output 'waves.png'
set title "Sine and Cosine"
set xlabel "x"
set ylabel "f(x)"
set grid
set xrange [-pi:pi]
set key top right

plot sin(x) title "sin(x)" with lines lw 2, \
     cos(x) title "cos(x)" with lines lw 2 dashtype 2
github-dark
set terminal pngcairo size 800,600
set output 'waves.png'
set title "Sine and Cosine"
set xlabel "x"
set ylabel "f(x)"
set grid
set xrange [-pi:pi]
set key top right

plot sin(x) title "sin(x)" with lines lw 2, \
     cos(x) title "cos(x)" with lines lw 2 dashtype 2
dracula
set terminal pngcairo size 800,600
set output 'waves.png'
set title "Sine and Cosine"
set xlabel "x"
set ylabel "f(x)"
set grid
set xrange [-pi:pi]
set key top right

plot sin(x) title "sin(x)" with lines lw 2, \
     cos(x) title "cos(x)" with lines lw 2 dashtype 2
nord
set terminal pngcairo size 800,600
set output 'waves.png'
set title "Sine and Cosine"
set xlabel "x"
set ylabel "f(x)"
set grid
set xrange [-pi:pi]
set key top right

plot sin(x) title "sin(x)" with lines lw 2, \
     cos(x) title "cos(x)" with lines lw 2 dashtype 2
github
set terminal pngcairo size 800,600
set output 'waves.png'
set title "Sine and Cosine"
set xlabel "x"
set ylabel "f(x)"
set grid
set xrange [-pi:pi]
set key top right

plot sin(x) title "sin(x)" with lines lw 2, \
     cos(x) title "cos(x)" with lines lw 2 dashtype 2

2. Plotting columns from a data file

reading two series out of a whitespace-separated file
horizon-dark
set terminal svg
set output 'temps.svg'
set title 'Daily Temperatures'
set xlabel 'Day'
set ylabel 'Degrees C'
set style data linespoints
set key outside

plot 'temps.dat' using 1:2 title 'High' lw 2, \
     'temps.dat' using 1:3 title 'Low' lw 2
atom-one-dark
set terminal svg
set output 'temps.svg'
set title 'Daily Temperatures'
set xlabel 'Day'
set ylabel 'Degrees C'
set style data linespoints
set key outside

plot 'temps.dat' using 1:2 title 'High' lw 2, \
     'temps.dat' using 1:3 title 'Low' lw 2
github-dark
set terminal svg
set output 'temps.svg'
set title 'Daily Temperatures'
set xlabel 'Day'
set ylabel 'Degrees C'
set style data linespoints
set key outside

plot 'temps.dat' using 1:2 title 'High' lw 2, \
     'temps.dat' using 1:3 title 'Low' lw 2
dracula
set terminal svg
set output 'temps.svg'
set title 'Daily Temperatures'
set xlabel 'Day'
set ylabel 'Degrees C'
set style data linespoints
set key outside

plot 'temps.dat' using 1:2 title 'High' lw 2, \
     'temps.dat' using 1:3 title 'Low' lw 2
nord
set terminal svg
set output 'temps.svg'
set title 'Daily Temperatures'
set xlabel 'Day'
set ylabel 'Degrees C'
set style data linespoints
set key outside

plot 'temps.dat' using 1:2 title 'High' lw 2, \
     'temps.dat' using 1:3 title 'Low' lw 2
github
set terminal svg
set output 'temps.svg'
set title 'Daily Temperatures'
set xlabel 'Day'
set ylabel 'Degrees C'
set style data linespoints
set key outside

plot 'temps.dat' using 1:2 title 'High' lw 2, \
     'temps.dat' using 1:3 title 'Low' lw 2

3. Inline datablock with a macro

gnuplot 5+ datablocks and macro expansion for reuse
horizon-dark
set macros
STYLE = "with linespoints pt 7 ps 1.5"

$Samples << EOD
1 2.1
2 3.4
3 2.9
4 4.2
EOD

set title "Inline Data"
plot $Samples using 1:2 @STYLE title 'measured'
atom-one-dark
set macros
STYLE = "with linespoints pt 7 ps 1.5"

$Samples << EOD
1 2.1
2 3.4
3 2.9
4 4.2
EOD

set title "Inline Data"
plot $Samples using 1:2 @STYLE title 'measured'
github-dark
set macros
STYLE = "with linespoints pt 7 ps 1.5"

$Samples << EOD
1 2.1
2 3.4
3 2.9
4 4.2
EOD

set title "Inline Data"
plot $Samples using 1:2 @STYLE title 'measured'
dracula
set macros
STYLE = "with linespoints pt 7 ps 1.5"

$Samples << EOD
1 2.1
2 3.4
3 2.9
4 4.2
EOD

set title "Inline Data"
plot $Samples using 1:2 @STYLE title 'measured'
nord
set macros
STYLE = "with linespoints pt 7 ps 1.5"

$Samples << EOD
1 2.1
2 3.4
3 2.9
4 4.2
EOD

set title "Inline Data"
plot $Samples using 1:2 @STYLE title 'measured'
github
set macros
STYLE = "with linespoints pt 7 ps 1.5"

$Samples << EOD
1 2.1
2 3.4
3 2.9
4 4.2
EOD

set title "Inline Data"
plot $Samples using 1:2 @STYLE title 'measured'