The histograms style is only relevant to 2D plotting. It produces a bar chart from a sequence of parallel data columns. Each element of the plot command must specify a single input data source (e.g. one column of the input file), possibly with associated tic values or key titles. Four styles of histogram layout are currently supported.
set style histogram clustered {gap <gapsize>}
set style histogram errorbars {gap <gapsize>} {<linewidth>}
set style histogram rowstacked
set style histogram columnstacked
set style histogram {title font "name,size" tc <colorspec>}

The default style corresponds to set style histogram clustered gap 2. In this style, each set of parallel data values is collected into a group of boxes clustered at the x-axis coordinate corresponding to their sequential position (row #) in the selected datafile columns. Thus if <n> datacolumns are selected, the first cluster is centered about x=1, and contains <n> boxes whose heights are taken from the first entry in the corresponding <n> data columns. This is followed by a gap and then a second cluster of boxes centered about x=2 corresponding to the second entry in the respective data columns, and so on. The default gap width of 2 indicates that the empty space between clusters is equivalent to the width of 2 boxes. All boxes derived from any one column are given the same fill color and/or pattern (see set style fill).

Each cluster of boxes is derived from a single row of the input data file. It is common in such input files that the first element of each row is a label. Labels from this column may be placed along the x-axis underneath the appropriate cluster of boxes with the xticlabels option to using.

The errorbars style is very similar to the clustered style, except that it requires additional columns of input for each entry. The first column holds the height (y value) of that box, exactly as for the clustered style.

2 columns:        y yerr          bar extends from y-yerr to y+err
3 columns:        y ymin ymax     bar extends from ymin to ymax
The appearance of the error bars is controlled by the current value of set errorbars and by the optional <linewidth> specification.

Two styles of stacked histogram are supported, chosen by the command set style histogram {rowstacked|columnstacked}. In these styles the data values from the selected columns are collected into stacks of boxes. Positive values stack upwards from y=0; negative values stack downwards. Mixed positive and negative values will produce both an upward stack and a downward stack. The default stacking mode is rowstacked.

The rowstacked style places a box resting on the x-axis for each data value in the first selected column; the first data value results in a box a x=1, the second at x=2, and so on. Boxes corresponding to the second and subsequent data columns are layered on top of these, resulting in a stack of boxes at x=1 representing the first data value from each column, a stack of boxes at x=2 representing the second data value from each column, and so on. All boxes derived from any one column are given the same fill color and/or pattern (see set style fill).

The columnstacked style is similar, except that each stack of boxes is built up from a single data column. Each data value from the first specified column yields a box in the stack at x=1, each data value from the second specified column yields a box in the stack at x=2, and so on. In this style the color of each box is taken from the row number, rather than the column number, of the corresponding data field.

Box widths may be modified using the set boxwidth command. Box fill styles may be set using the set style fill command.

Histograms always use the x1 axis, but may use either y1 or y2. If a plot contains both histograms and other plot styles, the non-histogram plot elements may use either the x1 or the x2 axis.

Examples: Suppose that the input file contains data values in columns 2, 4, 6, ... and error estimates in columns 3, 5, 7, ... This example plots the values in columns 2 and 4 as a histogram of clustered boxes (the default style). Because we use iteration in the plot command, any number of data columns can be handled in a single command. See plot for.

set boxwidth 0.9 relative
set style data histograms
set style histogram cluster
set style fill solid 1.0 border lt -1
plot for [COL=2:4:2] 'file.dat' using COL

This will produce a plot with clusters of two boxes (vertical bars) centered at each integral value on the x axis. If the first column of the input file contains labels, they may be placed along the x-axis using the variant command

plot for [COL=2:4:2] 'file.dat' using COL:xticlabels(1)

If the file contains both magnitude and range information for each value, then error bars can be added to the plot. The following commands will add error bars extending from (y-<error>) to (y+<error>), capped by horizontal bar ends drawn the same width as the box itself. The error bars and bar ends are drawn with linewidth 2, using the border linetype from the current fill style.

set errorbars fullwidth
set style fill solid 1 border lt -1
set style histogram errorbars gap 2 lw 2
plot for [COL=2:4:2] 'file.dat' using COL:COL+1

This shows how to plot the same data as a rowstacked histogram. Just to be different, this example lists the separate columns explicitly rather than using iteration.

set style histogram rowstacked
plot 'file.dat' using 2, ” using 4:xtic(1)

This will produce a plot in which each vertical bar corresponds to one row of data. Each vertical bar contains a stack of two segments, corresponding in height to the values found in columns 2 and 4 of the datafile.

Finally, the commands

set style histogram columnstacked
plot 'file.dat' using 2, ” using 4

will produce two vertical stacks, one for each column of data. The stack at x=1 will contain a box for each entry in column 2 of the datafile. The stack at x=2 will contain a box for each parallel entry in column 4 of the datafile.

Because this interchanges gnuplot's usual interpretation of input rows and columns, the specification of key titles and x-axis tic labels must also be modified accordingly. See the comments given below.

set style histogram columnstacked
plot ” u 5:key(1)            # uses first column to generate key titles
plot ” u 5 title columnhead  # uses first row to generate xtic labels

Note that the two examples just given present exactly the same data values, but in different formats.


newhistogram {"<title>" {font "name,size"} {tc <colorspec>}} 
             {lt <linetype>} {fs <fillstyle>} {at <x-coord>}

More than one set of histograms can appear in a single plot. In this case you can force a gap between them, and a separate label for each set, by using the newhistogram command. For example

set style histogram  cluster
plot newhistogram "Set A", 'a' using 1, ” using 2, ” using 3, \
     newhistogram "Set B", 'b' using 1, ” using 2, ” using 3

The labels "Set A" and "Set B" will appear beneath the respective sets of histograms, under the overall x axis label.

The newhistogram command can also be used to force histogram coloring to begin with a specific color (linetype). By default colors will continue to increment successively even across histogram boundaries. Here is an example using the same coloring for multiple histograms

plot newhistogram "Set A" lt 4, 'a' using 1, ” using 2, ” using 3, \
     newhistogram "Set B" lt 4, 'b' using 1, ” using 2, ” using 3

Similarly you can force the next histogram to begin with a specified fillstyle. If the fillstyle is set to pattern, then the pattern used for filling will be incremented automatically.

The at <x-coord> option sets the x coordinate position of the following histogram to <x-coord>. For example

set style histogram cluster
set style data histogram
set style fill solid 1.0 border -1
set xtic 1 offset character 0,0.3
plot newhistogram "Set A", \
     'file.dat' u 1 t 1, ” u 2 t 2, \
     newhistogram "Set B" at 8, \
     'file.dat' u 2 t 2, ” u 2 t 2

will position the second histogram to start at x=8.

Automated iteration over multiple columns

If you want to create a histogram from many columns of data in a single file, it is very convenient to use the plot iteration feature. See plot for. For example, to create stacked histograms of the data in columns 3 through 8
set style histogram columnstacked
plot for [i=3:8] "datafile" using i title columnhead

Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
Distributed under the gnuplot license (rights to distribute modified versions are withheld).