aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/gnuplot.md
blob: 4daee3a5275eaa748a26eebf7e40762a54598c7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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
```sh
# 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
```sh
# 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
```sh
# Plot two functions in the range 0-10.
plot [0:10] 10*x, 20*x
```

## Example: multiple data sets in plot
```sh
{{#include gnuplot/mem_lat.plot}}
```

On Linux x86_64, [`mem_lat.c`](gnuplot/mem_lat.c) provides an example which can
be run as follows.
```sh
{{#include gnuplot/plot.sh:3:9}}
```