Gnuplot 5.2.7

Linetypes, colors, and styles

In older gnuplot versions, each terminal type provided a set of distinct "linetypes" that could differ in color, in thickness, in dot/dash pattern, or in some combination of color and dot/dash. These colors and patterns were not guaranteed to be consistent across different terminal types although most used the color sequence red/green/blue/magenta/cyan/yellow. You can select this old behaviour via the command set colorsequence classic, but by default gnuplot version 5 uses a terminal-independent sequence of 8 colors.

You can further customize the sequence of linetype properties interactively or in an initialization file. See set linetype. Several sample initialization files are provided in the distribution package.

The current linetype properties for a particular terminal can be previewed by issuing the test command after setting the terminal type.

Successive functions or datafiles plotted by a single command will be assigned successive linetypes in the current default sequence. You can override this for any individual function, datafile, or plot element by giving explicit line prooperties in the plot command.

Examples:

plot "foo", "bar"                 # plot two files using linetypes 1, 2
plot sin(x) linetype 4            # use linetype color 4

In general, colors can be specified using named colors, rgb (red, green, blue) components, hsv (hue, saturation, value) components, or a coordinate along the current pm3d palette.

Examples:

plot sin(x) lt rgb "violet"       # one of gnuplot's named colors
plot sin(x) lt rgb "#FF00FF"      # explicit RGB triple in hexadecimal
plot sin(x) lt palette cb -45     # whatever color corresponds to -45
                                  # in the current cbrange of the palette
plot sin(x) lt palette frac 0.3   # fractional value along the palette

See colorspec, show colornames, hsv, set palette, cbrange. See also set monochrome.

Linetypes also have an associated dot-dash pattern although not all terminal types are capable of using it. Gnuplot version 5 allows you to specify the dot-dash pattern independent of the line color. See dashtype.

Colorspec

Many commands allow you to specify a linetype with an explicit color.

Syntax:

... {linecolor | lc} {"colorname" | <colorspec> | <n>}
... {textcolor | tc} {<colorspec> | {linetype | lt} <n>}

where <colorspec> has one of the following forms:

rgbcolor "colorname"    # e.g. "blue"
rgbcolor "0xRRGGBB"     # string containing hexadecimal constant
rgbcolor "0xAARRGGBB"   # string containing hexadecimal constant
rgbcolor "#RRGGBB"      # string containing hexadecimal in x11 format
rgbcolor "#AARRGGBB"    # string containing hexadecimal in x11 format
rgbcolor <integer val>  # integer value representing AARRGGBB
rgbcolor variable       # integer value is read from input file
palette frac <val>      # <val> runs from 0 to 1
palette cb <value>      # <val> lies within cbrange
palette z
variable                # color index is read from input file
bgnd                    # background color
black

The "<n>" is the linetype number the color of which is used, see test.

"colorname" refers to one of the color names built in to gnuplot. For a list of the available names, see show colornames.

Hexadecimal constants can be given in quotes as "#RRGGBB" or "0xRRGGBB", where RRGGBB represents the red, green, and blue components of the color and must be between 00 and FF. For example, magenta = full-scale red + full-scale blue could be represented by "0xFF00FF", which is the hexadecimal representation of (255 << 16) + (0 << 8) + (255).

"#AARRGGBB" represents an RGB color with an alpha channel (transparency) value in the high bits. An alpha value of 0 represents a fully opaque color; i.e., "#00RRGGBB" is the same as "#RRGGBB". An alpha value of 255 (FF) represents full transparency. Note: This convention for the alpha channel is backwards from that used by the "with rgbalpha" image plot mode in earlier versions of gnuplot.

The color palette is a linear gradient of colors that smoothly maps a single numerical value onto a particular color. Two such mappings are always in effect. palette frac maps a fractional value between 0 and 1 onto the full range of the color palette. palette cb maps the range of the color axis onto the same palette. See set cbrange. See also set colorbox. You can use either of these to select a constant color from the current palette.

"palette z" maps the z value of each plot segment or plot element into the cbrange mapping of the palette. This allows smoothly-varying color along a 3d line or surface. It also allows coloring 2D plots by palette values read from an extra column of data (not all 2D plot styles allow an extra column).

There are two special color specifiers: bgnd for background color and black.

Background color

Most terminals allow you to set an explicit background color for the plot. The special linetype bgnd will draw in this color, and bgnd is also recognized as a color. Examples:

# This will erase a section of the canvas by writing over it in the
# background color
set term wxt background rgb "gray75"
set object 1 rectangle from x0,y0 to x1,y1 fillstyle solid fillcolor bgnd
# This will draw an "invisible" line along the x axis
plot 0 lt bgnd

Linecolor variable

lc variable tells the program to use the value read from one column of the input data as a linetype index, and use the color belonging to that linetype. This requires a corresponding additional column in the using specifier. Text colors can be set similarly using tc variable.

Examples:

# Use the third column of data to assign colors to individual points
plot 'data' using 1:2:3 with points lc variable
# A single data file may contain multiple sets of data, separated by two
# blank lines.  Each data set is assigned as index value (see `index`)
# that can be retrieved via the `using` specifier `column(-2)`.
# See `pseudocolumns`.  This example uses to value in column -2 to 
# draw each data set in a different line color.
plot 'data' using 1:2:(column(-2)) with lines lc variable

Rgbcolor variable

You can assign a separate color for each data point, line segment, or label in your plot. lc rgbcolor variable tells the program to read RGB color information for each line in the data file. This requires a corresponding additional column in the using specifier. The extra column is interpreted as a 24-bit packed RGB triple. If the value is provided directly in the data file it is easiest to give it as a hexidecimal value (see rgbcolor). Alternatively, the using specifier can contain an expression that evaluates to a 24-bit RGB color as in the example below. Text colors are similarly set using tc rgbcolor variable.

Example:

# Place colored points in 3D at the x,y,z coordinates corresponding to
# their red, green, and blue components
rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
splot "data" using 1:2:3:(rgb($1,$2,$3)) with points lc rgb variable

Dashtype

In gnuplot version 5 the dash pattern (dashtype) is a separate property associated with each line, analogous to linecolor or linewidth. It is not necessary to place the current terminal in a special mode just to draw dashed lines. I.e. the command set term <termname> {solid|dashed} is now ignored. If backwards compatibility with old scripts written for version 4 is required, the following lines can be used instead:

if (GPVAL_VERSION >= 5.0) set for [i=1:9] linetype i dashtype i
if (GPVAL_VERSION < 5.0) set termoption dashed

All lines have the property dashtype solid unless you specify otherwise. You can change the default for a particular linetype using the command set linetype so that it affects all subsequent commands, or you can include the desired dashtype as part of the plot or other command.

Syntax:

dashtype N          # predefined dashtype invoked by number
dashtype "pattern"  # string containing a combination of the characters
                    # dot (.) hyphen (-) underscore(_) and space.
dashtype (s1,e1,s2,e2,s3,e3,s4,e4)  # dash pattern specified by 1 to 4
                    # numerical pairs <solid length>, <emptyspace length> 

Example:

# Two functions using linetype 1 but distinguished by dashtype
plot f1(x) with lines lt 1 dt solid, f2(x) with lines lt 1 dt 3

Some terminals support user-defined dash patterns in addition to whatever set of predefined dash patterns they offer.

Examples:

plot f(x) dt 3            # use terminal-specific dash pattern 3
plot f(x) dt ".. "        # construct a dash pattern on the spot
plot f(x) dt (2,5,2,15)   # numerical representation of the same pattern
set dashtype 11 (2,4,4,7) # define new dashtype to be called by index
plot f(x) dt 11           # plot using our new dashtype

If you specify a dash pattern using a string the program will convert this to a sequence of <solid>,<empty> pairs. Dot "." becomes (2,5), dash "-" becomes (10,10), underscore "_" becomes (20,10), and each space character " " adds 10 to the previous <empty> value. The command show dashtype will show both the original string and the converted numerical sequence.

Linestyles vs linetypes

A linestyle is a temporary association of properties linecolor, linewidth, dashtype, and pointtype. It is defined using the command set style line. Once you have defined a linestyle, you can use it in a plot command to control the appearance of one or more plot elements. In other words, it is just like a linetype except for its lifetime. Whereas linetypes are permanent (they last until you explicitly redefine them), linestyles last until the next reset of the graphics state.

Examples:

# define a new line style with terminal-independent color cyan,
# linewidth 3, and associated point type 6 (a circle with a dot in it).
set style line 5 lt rgb "cyan" lw 3 pt 6
plot sin(x) with linespoints ls 5          # user-defined line style 5