Format

The format of the tic-mark labels can be set with the set format command.

Syntax:

     set format {<axes>} {"<format-string>"}
     set format {<axes>} {'<format-string>'}
     show format

where <axes> is either x, y, z, xy, x2, y2 or nothing (which is the same as xy). The length of the string representing a ticmark (after formatting with 'printf') is restricted to 100 characters. If the format string is omitted, the format will be returned to the default "%g". For LaTeX users, the format "$%g$" is often desirable. If the empty string "" is used, no label will be plotted with each tic, though the tic mark will still be plotted. To eliminate all tic marks, use set noxtics or set noytics.

Newline ( \n) is accepted in the format string. Use double-quotes rather than single-quotes to enable such interpretation. See also syntax.

The default format for both axes is "%g", but other formats such as "%.2f" or "%3.0em" are often desirable. Anything accepted by 'printf' when given a double precision number, and accepted by the terminal, will work. Some other options have been added. If the format string looks like a floating point format, then gnuplot tries to construct a reasonable format.

Characters not preceded by "%" are printed verbatim. Thus you can include spaces and labels in your format string, such as "%g m", which will put " m" after each number. If you want "%" itself, double it: "%g %%".

The acceptable formats (if not in date/time mode) are:

Format Specifiers
Format   Explanation
%f   floating point notation
%e or %E   exponential notation; an "e" or "E" before the power
%g or %G   the shorter of %e (or %E) and %f
%x or %X   hex
%o or %O   octal
%t   mantissa to base 10
%l   mantissa to base of current logscale
%s   mantissa to base of current logscale; scientific power
%T   power to base 10
%L   power to base of current logscale
%S   scientific power
%c   character replacement for scientific power
%P   multiple of pi

A 'scientific' power is one such that the exponent is a multiple of three. Character replacement of scientific powers ("%c") has been implemented for powers in the range -18 to +18. For numbers outside of this range the format reverts to exponential.

Other acceptable modifiers (which come after the "%" but before the format specifier) are "-", which left-justifies the number; "+", which forces all numbers to be explicitly signed; "#", which places a decimal point after floats that have only zeroes following the decimal point; a positive integer, which defines the field width; "0" (the digit, not the letter) immediately preceding the field width, which indicates that leading zeroes are to be used instead of leading blanks; and a decimal point followed by a non-negative integer, which defines the precision (the minimum number of digits of an integer, or the number of digits following the decimal point of a float).

Some releases of 'printf' may not support all of these modifiers but may also support others; in case of doubt, check the appropriate documentation and then experiment.

Examples:

     set format y "%t"; set ytics (5,10)          # "5.0" and "1.0"
     set format y "%s"; set ytics (500,1000)      # "500" and "1.0"
     set format y "+-12.3f"; set ytics(12345)     # "+12345.000  "
     set format y "%.2t*10^%+03T"; set ytic(12345)# "1.23*10^+04"
     set format y "%s*10^{%S}"; set ytic(12345)   # "12.345*10^{3}"
     set format y "%s %cg"; set ytic(12345)       # "12.345 kg"
     set format y "%.0P pi"; set ytic(6.283185)   # "2 pi"
     set format y "%.0P%%"; set ytic(50)          # "50%"

     set log y 2; set format y '%l'; set ytics (1,2,3)
     #displays "1.0", "1.0" and "1.5" (since 3 is 1.5 * 2^1)

There are some problem cases that arise when numbers like 9.999 are printed with a format that requires both rounding and a power.

If the data type for the axis is date/time, the format string must contain valid codes for the 'strftime' function (outside of gnuplot, type "man strftime"). See set timefmt for a list of the allowed input format codes.

In date/time mode, the acceptable formats are:

Date/Time Format Specifiers
Format   Explanation
%a   abbreviated name of day of the week
%A   full name of day of the week
%b or %h   abbreviated name of the month
%B   full name of the month
%d   day of the month, 1–31
%D   shorthand for "%m/%d/%y"
%H or %k   hour, 0–24
%I or %l   hour, 0–12
%j   day of the year, 1–366
%m   month, 1–12
%M   minute, 0–60
%p   "am" or "pm"
%r   shorthand for "%I:%M:%S %p"
%R   shorthand for %H:%M"
%S   second, 0–60
%T   shorthand for "%H:%M:%S"
%U   week of the year (week starts on Sunday)
%w   day of the week, 0–6 (Sunday = 0)
%W   week of the year (week starts on Monday)
%y   year, 0-99
%Y   year, 4-digit

Except for the non-numerical formats, these may be preceded by a "0" ("zero", not "oh") to pad the field length with leading zeroes, and a positive digit, to define the minimum field width (which will be overridden if the specified width is not large enough to contain the number). There is a 24-character limit to the length of the printed text; longer strings will be truncated.

Examples:

Suppose the text is "76/12/25 23:11:11". Then

     set format x                 # defaults to "12/25/76" \n "23:11"
     set format x "%A, %d %b %Y"  # "Saturday, 25 Dec 1976"
     set format x "%r %d"         # "11:11:11 pm 12/25/76"

Suppose the text is "98/07/06 05:04:03". Then

     set format x "%1y/%2m/%3d %01H:%02M:%03S"  # "98/ 7/  6 5:04:003"

See also set xtics for more information about tic labels.