Axis Ranges, Tics and Log Scales in Gnuplot

Three settings control gnuplot axes: set xrange and set yrange fix the visible window, set xtics and set ytics place the tick marks, and set logscale switches an axis to logarithmic spacing. This script combines all three on fast-growing data.

The example uses growth.dat: a step number in column 1 and a rapidly growing count in column 2, spanning 10 to 9,800 — exactly the kind of data a linear axis squashes flat.

1  10
2  45
3  130
4  420
5  1350
6  4100
7  9800
set xrange [0:8]
set yrange [1:10000]
set logscale y 10
set format y "10^%T"
set ytics (10, 100, 1000, 10000)
set mxtics 5
set grid
set title "Growth on a Log Scale"
set xlabel "Step"
set ylabel "Count"
plot "growth.dat" using 1:2 with linespoints linewidth 2 pointtype 7 title "Count"

What each part does

Ranges are written as set xrange [min:max]. Either bound can be left empty ([ :100]) to keep autoscaling on that side, and set autoscale x restores full autoscaling. Fixing the range is what makes a series of figures comparable: every plot shows the same window.

set logscale y 10 makes the y axis logarithmic in base 10 (base 2 is common for computing topics: set logscale y 2). On a log axis equal distances mean equal ratios, so exponential growth becomes a straight line. Major tics are placed explicitly here with the list form set ytics (10, 100, 1000, 10000) — for log axes the list form is clearer than the start/increment/end form. set format y "10^%T" renders the tic labels as powers of ten using the enhanced-text placeholder %T (the power itself). Remove the format line if you prefer plain 10, 100, 1000 labels.

set mxtics 5 adds minor tics between the major x tics — minor tics are the smaller unlabeled marks that make values easier to read off. The y-axis equivalent is set mytics, which on a log axis places the 2–9 subdivision marks automatically.

Variants and going further

The start/increment/end tic form is handy on linear axes: set xtics 0, 10, 100 marks every 10 units from 0 to 100. Custom text labels work too: set xtics ("low" 1, "mid" 2, "high" 3). Angles help crowded date or category axes: set xtics rotate by -45. And set format x "%.0f" or "%.2e" gives full control of numeric label formatting with printf-style specifiers.

Common mistakes

  • Log scale with zero or negative data: logarithms are undefined there, so gnuplot drops those points (watch for “Log scale range must be greater than zero” or missing points). Filter or offset the data, or keep a linear axis.
  • Empty plot after setting a range: the range and the data disagree — often a transposed file or a range typed for the other axis. Comment out the range lines, plot once with autoscaling, and read the real extents from the result.

Related tutorials: Plot CSV Data in Gnuplot, 3D Plots with splot. See also the full Gnuplot Tutorials index.

Try it online: Toggle the set logscale y 10 line in and out in the online terminal to see the same data linear versus logarithmic. Paste the script into the Gnuplot Online terminal and run it in your browser — no install needed. To run gnuplot locally instead, see the installation guide and the download page.

Go deeper: For a systematic walk through gnuplot from first plots to publication-ready figures, see Gnuplot in Action by Philipp K. Janert — Janert is a gnuplot developer, and the book is the most complete tutorial reference for the program. Affiliate link: see our Affiliate Disclosure.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *