8.2.4 Barcharts and histograms

The following plot styles allow barcharts to be produced:

  • boxes

  • impulses

  • wboxes

These styles differ in where the horizontal interfaces between the bars are placed along the abscissa axis and how wide the bars are. In the boxes plot style, the interfaces between the bars are at the midpoints between the specified data points by default (see, for example, Figure 8.1a). Alternatively, the widths of the bars may be set using the set boxwidth command. In this case, all of the bars will be centered on their specified $x$-coordinates, and have total widths equalling that specified in the set boxwidth command. Consequently, there may be gaps between them, or they may overlap, as seen in Figure 8.1(b).

\includegraphics[width=\textwidth ]{examples/eps/ex_barchart2}
Figure 8.1: A gallery of the various bar chart styles which Pyxplot can produce. See the text for more details.

Having set a fixed box width, the default behaviour of scaling box widths automatically may be restored either with the unset boxwidth command, or by setting the boxwidth to a negative width.

In the wboxes plot style, the width of each bar is specified manually as an additional column of the input data file. This plot style expects three columns of data to be provided: the $x$- and $y$-coordinates of each bar in the first two, and the width of the bars in the third. Figure 8.1(c) shows an example of this plot style in use.

Finally, in the impulses plot style, the bars all have zero width; see Figure 8.2(c) for an example.

In all of these plot styles, the bars originate from the line $y=0$ by default, as is normal for a histogram. However, should it be desired for the bars to start from a different vertical line, this may be achieved by using the set boxfrom command, for example:

set boxfrom 5

In this case, all of the bars would now originate from the line $y=5$. Figure 8.2(b) shows the kind of effect that is achieved; for comparison, Figure 8.2(a) shows the same bar chart with the boxes starting from their default position of $y=0$.

\includegraphics[width=\textwidth ]{examples/eps/ex_barchart1}
Figure 8.2: A second gallery of the various bar chart styles which Pyxplot can produce. See the text for more details. The script and data file used to produce this image are available on the Pyxplot website at http://www.pyxplot.org.uk/examples/Manual/03barchart1/.

The bars may be filled using the with fillcolor modifier, followed by the name of a color:

plot 'data.dat' with boxes fillcolor blue
plot 'data.dat' with boxes fc 4

Figures 8.1(b) and (d) demonstrate the use of filled bars.

The boxes and wboxes plot styles expect identically-formatted data when used on two- and three-dimensional plots; in the latter case, all bars are drawn in the plane $z=0$. The impulses plot style takes an additional column of data on three-dimensional plots, specifying the $z$-coordinate at which each impulse should be drawn.

Stacked bar charts

If multiple data points are supplied to the boxes or wboxes plot styles at a common $x$-coordinate, then the bars are stacked one above another into a stacked barchart. Consider the following data file:

1 1
2 2
2 3
3 4

The second bar at $x=2$ would be placed on top of the first, spanning the range $2<y<5$, and having the same width as the first. If plot colors are being automatically selected from the palette, then a different palette color is used to plot the upper bar.