Gnuplot

Table of Contents

Professional plotting tool

1. CLI

  • -e "command1; command2; ...
    • -persist
  • -c <scriptfile> ARG1 ARG2 ...

2. Set

2.1. Input

  • set datafile
    • separator {whitespace | tab | comma | "chars"}
    • missing {"<string>" | NaN}

2.2. Output

  • set output <filename>
    • The filename is a string variable. Note that strings can be concatenated with . in the middle.
    • The output can be piped with "|<command>"
  • set term
    • lua tikz: TeX
    • jpeg
    • png
      • tiny | small | medium | large | giant
      • font "<face> {, <pointsize>}", font <face> <pointsize>
      • fontscale <scale>
      • size <x>, <y>
      • background <rgb_color>
    • gif, svg, pdf
    • canvas
    • qt: Interactive

2.3. Annotations

Legend

  • set key
    • on | off
    • default
    • { inside | outside | fixed } | { lmargin | rmargin | tmargin | bmargin } | { at <position> }
    • { left | right | center } { top | bottom | center }
      • { l | r | c } { t | b | c }
    • { vertical | horizontal } { Left | Right }
    • title {"<text>"} {{no}enhanced} {center | left | right}

Label

  • set label {"<label text>"} {at <position>} {left | center | right}
  • set {x|x2|y|y2|z|t}label {"label"} {offset <offset>} {rotate by <degrees> | rotate parallel | norotate}

Tick mark

  • set {x|x2|y|y2|z|t}tics
    • {axis | border} {{no}mirror} {in | out} {front | back}
    • {no}rotate {by <ang>}
    • offset <offset> | nooffset
    • left | right | center | autojustify
    • {add} {autofreq | <incr> | <start>, <incr> {, <end>} | ({"<label>"} <pos> {<level>} {,...})}

2.4. Plot

  • set {x|x2|y|y2|z|cb|r|t|u|v}range [{{<min>}:{<max>}}] {{no}reverse} {{no}writeback} {{no}extend} | restore
  • set origin <x> <y>
  • set style
    • function <style>
    • data <style>
    • <style>

3. Fit

  • fit {<ranges>} <expression>
  • '<datafile>' {datafile-modifiers}
  • {{unitweights} | {y|xy|z}error | errors <var1>{, <var2>, ...}}
  • via '<parameter file>' | <var1>{, <var2>, ...}
  • e.g. fit f(x) 'data' using 1:2 via a, b, f(x) = ax + b
  • Fit 1 dependent variable to up to 12 independent variables.
  • It uses the nonlinear least-square Levenberg-Marquardt algorithm

4. Plot

  • {[<trange>]}[<xrange>][<yrange>][<x2range>][<y2range>]...
  • for [<var>=<start>:<end>:<increment>] for [<var> in "word1 word2 word3 ..."]

4.1. Data

  • 'filename'
  • every point_incr:block_incr:start_point:start_block:end_point:end_block
    • end_block cannot be omitted.
    • The count starts from 0.
    • point is the record, and block is the list of records separated by black lines. (not the case for matrix)
  • skip N: Ignore the first N lines
  • using N:M:{K:...} u: Specify which column to use in which order.
  • smooth: perform filtering.
    • unique | frequency | fnormal | cumulative | cnormal: the distribution
    • kdensity {bandwidth} {period}: kernel density estimate
    • csplines | acsplines | mcsplines | bezier | sbezier: curve interpolation
      • csplines:
      • acsplines: Natural Smoothing Splines
        • The third column is used as the weights.
      • mcsplines: Monotomic Piecewise Cubic Interpolation
      • bezier: Use the middle points as the control points
    • unwrap | zsort
  • bins=N: sort into equal-sized intervals, histogram.
    • binrange [LOW:HIGH]: the total range of data
    • binwidth=WIDTH: width of a single bin

4.1.1. Special Filenames

  • '': The previous input
  • '+' , - '++': Samples generated
  • '-': Inline data
  • "< <command>": Piped data

4.2. Function

4.2.1. Parametric

  • set parametric to enable
  • the function must be given in pairs (or triplets for splot).

4.3. Style

  • t, title <text> | notitle title columnheader title columnheader(N) at {beginning | end | <screenx>, <screeny>}
    • t
    • title "" is equivalent to notitle
  • w with <style>: style is one of
    • lines points linespoints financebars dots impulses labels surface steps fsteps histeps arrows vectors xerrorbar xerrorlines yerrorbar yerrorlines xyerrorbars xyerrorlines parallelaxes
    • boxes boxerrorbars boxxyerror isosurface boxplot candlesticks circles zerrorfill ellipses filledcurves fillsteps histograms image pm3d rgbalpha rgbimage polygons
    • table
  • linetype, lt: 0 Dotted line
  • linewidth lw
  • linecolor, lc: "color"
  • pointtype pt
    • -1: No point
    • 0: Dot
    • 1: Plus
    • 2: Times
    • 3: Asterisk
    • 4: Box
    • 5: Filled Box
  • pointsize ps
  • arrowstyle as
  • fill fs
  • Multiple plots can drawn on the same canvas by joining them with ,.
  • \ Can be used at the end of a line to include a newline.

4.4. Multiplot

  • set multiplot
    • layout n,m
  • unset multiplot

5. Enhanced Text Mode

[no]enhanced option in the legend, label enable (or disable) the enhanced text mode.

Enhanced mode allows writing complex formatted text with ASCII.

  • _, ^ subscript and superscript
  • {/<fontfamily>:<typeface>=N ...} set font
  • \U+OOOO Unicode

Author: Jeemin Kim

Created: 2026-07-12 Sun 14:28