Gnuplot

From wikinotes

gnuplot is a program that helps you render graphs inside/outside your console.
You can record statistics over time, then compare them in graphs.

Example

From Point Data

echo '
1 1
2 4' | \
  gnuplot -e '
    set terminal dumb; `# render ASCII
    plot "/dev/stdin"  `# read from stdin\
      using 1:2        `# using col as x:y` \
      with lines       `# lines instead of dots`;'
    4 +--------------------------------------------------------------------+
      |             +             +            +             +        **** |
      |                                     "/dev/stdin" using 0:1 ******* |
  3.5 |-+                                                      ****      +-|
      |                                                     ***            |
      |                                                  ***               |
      |                                              ****                  |
    3 |-+                                         ***                    +-|
      |                                       ****                         |
      |                                    ***                             |
  2.5 |-+                              ****                              +-|
      |                             ***                                    |
      |                         ****                                       |
    2 |-+                    ***                                         +-|
      |                  ****                                              |
      |               ***                                                  |
      |            ***                                                     |
  1.5 |-+      ****                                                      +-|
      |     ***                                                            |
      | ****        +             +            +             +             |
    1 +--------------------------------------------------------------------+
      0            0.2           0.4          0.6           0.8            1

Linear Equations

Single Line

# plot.txt

f(x)=2+(x)*(x)
set xrange [0:10]
set yrange [0:10]
plot f(x)
with lines

Multiple Lines

downpayment(x)=200+(40*x)
house(x)=800*(1.05**x)

set xrange [1:10]
plot house(x), downpayment(x)
with lines

Render

gnuplot -p plot.txt

Syntax Basics

# 1x line. csv of x/y
# 
# INPUT:
#   1 2
#   2 5
#   3 7
plot "out.csv" with lines  

# 1x line, select columns for x/y (using col2==x, col3==y)
#
# INPUT:
#   foo  1 2
#   bar  2 5
#   baz  3 7
plot "out.csv" using 2:3  with lines    # using x:y


# 3x lines, a sample taken for each on y
#
# INPUT:
#  2020-01-01  1  1  1
#  2020-01-02  2  3  5
#  2020-01-03  3  9 10
plot "out.csv" using 1:2 title 'foo', `# col2` \
     "out.csv" using 1:3 title 'bar', `# col3` \
     "out.csv" using 1:4 title 'baz'  `# col4`;

# 3x lines, one per file
#
# EACH FILE 2-DIMENSIONAL CSV:
#    1 1
#    1 3
#    1 9
plot "foo.csv" title 'foo', \
     "bar.csv" title 'bar', \
     "baz.csv" title 'baz';

# You CANNOT have empty csv columns in your data.
# either every entry must be represented on every line,
# or you need to process your data so that it is filtered into different files.