gnuplot (1)
# Launch interactive shell.
gnuplot
# Launch interactive shell.
gnuplot [opt]
opt:
-p ................ persist plot window
-c <file> ......... run script file
-e "<cmd1>; .." ... run cmd(s)
Frequently used configuration
# Plot title.
set title "the plot"
# Labels.
set xlabel "abc"
set ylabel "def"
# Grid.
set grind
# Output format, 'help set term' for all output formats.
set term svg
# Output file.
set output "out.svg"
# Make axis logarithmic to given base.
set logscale x 2
# Change separator, default is whitespace.
set datafile separator ","
Plot
# With specific style (eg lines, linespoint, boxes, steps, impulses, ..).
plot "<data_file>" with <plot_style>
> cat data.txt
1 1 3
2 2 2
3 3 1
4 2 2
# Plot specific column.
plot "data.txt" using 1:2, "data.txt" using 1:3
# Equivalent using the special file "", which re-uses the previous input file.
plot "data.txt" using 1:2, "" using 1:3
# Plot piped data.
plot "< head -n2 data.txt"
# Plot with alternate title.
plot "data.txt" title "moose"
Example: Specify range directly during plot
# Plot two functions in the range 0-10.
plot [0:10] 10*x, 20*x
Example: multiple data sets in plot
# file: mem_lat.plot
set title "memory latency (different strides)"
set xlabel "array in KB"
set ylabel "cycles / access"
set logscale x 2
plot "stride_32.txt" title "32" with linespoints, \
"stride_64.txt" title "64" with linespoints, \
"stride_128.txt" title "128" with linespoints, \
"stride_256.txt" title "256" with linespoints, \
"stride_512.txt" title "512" with linespoints
On Linux x86_64, mem_lat.c
provides an example which can
be run as follows.
gcc -o mem_lat mem_lat.c -g -O3 -Wall -Werror
for stride in 32 64 128 256 512; do \
taskset -c 1 ./mem_lat 128 $stride | tee stride_$stride.txt ; \
done
gnuplot -p -c mem_lat.plot
Example: multiple plot in the same figure
# file: notion.plot
set terminal pngcairo size 1000,700 enhanced font 'Verdana,10'
set output 'results/dashboard.png'
set multiplot title strftime("%Y-%m-%d", time(0))
set origin 0,0.5
set size 1,0.48
#set title 'Distribution of Scores'
#set style fill transparent solid 0.5
set style histogram clustered
set style fill solid 0.6
set xlabel 'Score'
set ylabel 'Count'
set grid y
plot 'results/distribute_2024.txt' using 1:2 with boxes lc rgb "blue" title '2024', \
'results/distribute_2025.txt' using 1:2 with boxes lc rgb "red" title '2025'
set origin 0,0
set size 0.5,0.5
#set title 'Score Trend By Year'
set xlabel 'Weeks in year'
set ylabel 'Score per week'
plot 'results/trend_2024.txt' using 1:9 with lines lw 2 lc rgb "blue" title '2024', \
'results/trend_2025.txt' using 1:9 with lines lw 2 lc rgb "red" title '2025'
set origin 0.5,0
set size 0.5,0.5
#set title 'Score Trend At All Times'
set xlabel 'Weeks in year'
set ylabel 'Avg score at all times'
plot 'results/sumtrend_2024.txt' using 1:9 with lines lw 2 lc rgb "blue" title '2024', \
'results/sumtrend_2025.txt' using 1:9 with lines lw 2 lc rgb "red" title '2025'
unset multiplot