Chapter 5. Doing it with style
This chapter covers
The following three chapters describe the different ways to control the appearance of a plot: how to make it look just right. In this chapter, we’ll discuss the various ways to display data, and in the next chapter we’ll talk about all the other stuff that goes onto a plot, such as labels, borders, arrows, and similar decorations. Since axes and their labels can provide so much relevant information about a plot, they’ve been given their own chapter (chapter 7) which is the third and last in this part.
This chapter consists of three parts. First I describe the syntax for choosing a specific style for a plot. Then I’ll give a comprehensive, illustrated catalog of available styles. And finally, I’ll talk about ways you can define your own custom styles.
Only the first section in this chapter is required reading, because here is where I explain how to choose plot styles and where I introduce the important concept of terminal capabilities. For the rest of this chapter, feel free to just look at the figures so that you get a sense for the kinds of plots that gnuplot can create. You can always come back to this chapter when you need a specific plot type.
Different types of data call for different display styles. For instance, it makes sense to plot a smooth function with one continuous line, but to use separate symbols for a sparse data set where each individual point counts. Experimental data often requires error bars together with the data, whereas counting statistics call for histograms. Choosing an appropriate style for the data leads to graphs that are both informative and aesthetically pleasing.
There are two ways to choose a style for the data: inline, as part of the plot command, or globally, using the set style directive. Let’s talk about inline styles first, and then come back to global preferences later, once we’ve had a chance to introduce the notion of terminal capabilities, because it is up to the terminal which styles are actually available.
We have already seen inline styles in chapter 2: by giving the with keyword as part of the plot command, we can specify which style to use:
As usual, keywords can be abbreviated to the shortest unambiguous form, so we’d probably write w l, w linesp or w lp, and so on.
In graphical analysis, we often want to plot several similar data sets together on the same plot, usually so that we can compare them directly to one another:
All of these are plotted using the same style (with lines). Now the question is: which curve is which (see figure 5.1)?
Gnuplot helps us here by plotting each curve with a different line pattern (or different symbol, or different color, depending on the specific style chosen). Styles are chosen from a list of available patterns. If we need to plot more data sets than there are different styles, the selection begins again at the beginning.
We can overrule this automatic progression of plot styles by fixing the specific style to use:
This will plot the second and third column in the data file using the second style from the list of available styles for the current terminal. Fixing a specific style like this doesn’t affect the way the internal style counter is incremented, so the fourth column of the data will be displayed using the third style from the selection.
All this brings up the question: how many styles are there, and what are they? There’s no absolute answer to this question; it all depends on the output format, or rather, the terminal.
Gnuplot itself knows little about rendering a graph—this is left to the individual terminal devices. This way, gnuplot itself makes no assumptions about the platform it is running on and can be very portable. Output devices obviously differ widely in their capabilities—we can’t get color plots from a black-and-white printer. On the other hand, an interactive color terminal (such as X11) gives us color, but possibly only a smaller selection of patterns and available fonts.
Gnuplot has a built-in command called test that generates a standard test image. The test image shows all available line styles and fill patterns, and also attempts to demonstrate more advanced terminal capabilities, such as the ability to rotate text through an arbitrary angle. To use the test command, we first need to select the terminal we are interested in and set the name of the output file (if it’s not an interactive terminal) like so:
Note that the command is test—not plot test!
Along the right side of figure 5.2 we see the available line and symbol styles, fill patterns along the bottom, and line widths on the left side. We can also see what kinds of arrows the terminal supports, and whether it has the ability to rotate text. For a PostScript terminal as shown in the figure, all these features are supported.
Figure 5.2. The standard test image to demonstrate terminal capabilities, shown here for the PostScript terminal

Although inline styles give us a lot of control over the detailed representation of the data, they can be clumsy, in particular in large plot commands containing many data sets. This is where global styles come in.
By default, data (from a file) is plotted using the points style, while functions are plotted with lines. We can change these defaults using the set command, which we introduced in chapter 4. To specify the global defaults, we can use
Here, the {style} parameter can either be a style family (such as lines or points), or a specific style (such as lines 3). If only the family is indicated, gnuplot will iterate through all available styles in that family as usual, but if we choose one specific style, only that one will be used for all curves. Inline styles override global styles, as you would expect.
Now that we know how to choose styles, it’s time to look at the possible choices. So, let’s take a tour of the big catalog of available plot styles.
There are well over two dozen styles available in gnuplot. Here we look at those most useful for ordinary, two-dimensional data. We’ll encounter some additional styles in chapter 8 on multidimensional plots.
There are four styles I would call “core” styles, because they are so generally useful: with points, with lines, with linespoints, and with dots. These styles represent data with simple symbols or lines on the plot (see figure 5.3).
The points style plots a small symbol for each data point. The symbols aren’t connected to each other. This is the default style for data (see figure 5.3).
The size of the symbol can be changed globally using the set pointsize command. The parameter is a multiplier, defaulting to 1.0:
It is also possible to change the pointsize inline:
The lines style does not plot individual data points, only straight lines connecting adjacent points. This is the default style for functions, and the preferred style for dense data sets without too much noise.
Many aspects of lines, including their width and color, can be customized using set style line. Since lines are such fundamental objects, I have collected all this material in a separate section at the end of this chapter for easier reference (section 5.3).
The linespoints style is a combination of the previous two: each data point is marked with a symbol, and adjacent points are connected with straight lines. This style is mostly useful for sparse data sets.
The dots style prints a “minimal” dot (a single pixel for bitmap terminals) for each data point. This style is occasionally useful for very large, unsorted data sets (such as large scatter plots). Figure 1.2 in chapter 1 was drawn using dots.
Box styles, which draw a box of finite width, are sometimes useful for counting statistics, or for other data sets where the x values cannot take on a continuous spectrum of values.
Gnuplot offers three styles to generate steplike graphs, consisting only of vertical and horizontal lines (see figure 5.4). The only difference between the three styles is the location of the vertical step:
.
histeps style places the vertical step midway between adjacent x values.
.
steps style places the vertical step at the end of the bin.
.
fsteps style places the vertical step at the front of the bin.
Figure 5.4. The three steps styles. The same data set is shown three times (vertically shifted). Individual data points are represented by symbols; the three steps styles are shown in different line styles. Note how different the same data set can appear, depending on the exact location of the vertical steps.

If in doubt, the histeps style is probably the most useful one.
In contrast to the step styles from the previous section, the boxes style plots a box centered at the given x coordinate from the x axis (not from the graph border) to the y coordinate (see figure 5.5). The width of the box can be set in one of three ways:
- Supplied as third parameter to using.
- Set globally through the set boxwidth option.
- Otherwise, boxes are sized automatically to touch adjacent boxes.
Figure 5.5. Box and impulse styles. The widths of boxes can be set globally or for each box individually. The second data set uses a fixed width (enclosed in parentheses in the using directive); the third one reads values for variable box widths from file.

If a third column is supplied in the using directive, it is interpreted as the total width of the box in the same coordinates that are used for the x axis. The set boxwidth option has the following syntax:
The size parameter can either be a measure of the absolute size of the box in x axis coordinates, or it can denote a fraction of the default box size, which is the width of the box if it touches adjacent boxes. If absolute mode isn’t stated explicitly, relative sizing is assumed. A boxwidth of -2 can be used to force automatic sizing of boxes (with adjacent boxes touching each other). The impulses style is similar to the boxes style with a boxwidth set to zero. The examples in figure 5.5 make this more clear.
Boxes can be filled or shaded, according to the value of the set style fill option. It has the following syntax:
Density is a numeric value between 0.0 (empty) and 1.0 (solid); the color used is the same as the current line type. Available fill patterns vary from terminal to terminal. Use the test command to see what’s available. By default, each box is bounded by a border in the current linetype. This can be changed using the border attribute. The border can be turned off entirely using noborder.
The histogram styles are a recent addition to gnuplot and are somewhat of a departure from gnuplot’s usual processing model, in that they have the concept of a data set. The overall appearance of the plot depends on both row and column information simultaneously.
Histograms are the result of counting statistics. For the sake of discussion, let’s assume that there are three parties (Red, Blue, and Green) and we want to show the number of votes for each party. The outcome of a single election can be shown easily using, for instance, the histeps style.
But what to do if elections are held annually, and we want to show the results for a number of years in one plot? To make matters concrete, let’s consider a specific data file, shown in listing 5.1.
Listing 5.1. Data for figure 5.6 and figure 5.7
One possible solution would be to plot the data as a regular time series (see figure 5.6):
Figure 5.6. Election results as a time series. The data file is shown in listing 5.1.

Often this is exactly what we want, but this format can be clumsy, in particular if there are many competing parties or if there is a lot of variation year over year. The histogram style offers an alternative.
Using set style histogram clustered generates a sequence of histograms (see figure 5.7). Each histogram corresponds to one row in the input file (in our example, this corresponds to one year):
Figure 5.7. Election results using set style histogram clustered. This is the same data set as in figure 5.6.

Instead of inline styles, we can use global styles and achieve the same result:
For all of the histogram styles, it is usually a good idea to have the boxes filled to make them more easily distinguishable, and so we have enabled this option here. We can control the spacing between consecutive histograms using the optional gap parameter to the set style command: set style histogram clustered gap 2. The size of the gap is measured in multiples of individual boxes in the histograms. (To create gaps within each histogram, so that neighboring boxes don’t touch each other, use set boxwidth.)
Keep in mind that the way gnuplot reads the data file for histograms is a bit unusual: each new row generates a new histogram cluster, but the histogram style accepts only a single column in the using directive. We therefore have to list the file repeatedly in the same plot command to generate meaningful histograms, as shown previously.
Finally, the labels gnuplot places along the x axis aren’t very meaningful. We can either set explicit labels for each histogram using the set xtics add command or we can read a textual label from the data file using the function xticlabels() (or xtic() for short). The effect of the latter is demonstrated in figure 5.8. Both of these commands will be treated in more detail in chapter 7 on axes.
Figure 5.8. Election results using set style histogram rowstacked. This is the same data set yet again. Note the effect of the xtic() function, which is used to read x axis labels directly from the data file.

Besides the clustered histogram style we looked at so far, there is also a stacked style. Using this style, the individual boxes aren’t placed next to one another, but stacked on top of each other, so that each vertical box comprises an entire histogram. By default, adjacent boxes touch each other, but as usual, set boxwidth can be used to control the width of individual boxes (see figure 5.8).
There are two additional histogram styles, which I won’t describe here in detail, since they’re similar to the ones we discussed already. The set style histogram errorbars style is similar to the clustered style, except that it reads two values for each box, the second being the uncertainty in the data, represented with a standard errorbar. The set style histogram columnstacked style is equivalent to the rowstacked style, except that each vertical box is built from a single column (not row) in the input file.
One last directive related to histograms is newhistogram (see figure 5.9). It can be used to have several sets of clustered histograms on the same plot. An example will suffice:
The syntax for the newhistogram command is a bit unintuitive (I still tend to get it wrong), so let me point out the salient features: the newhistogram keyword is followed by a mandatory string label (an empty string is permitted), a mandatory comma, and then the rest of the plot command follows, starting with the filename.
Histograms such as those discussed in this section look good and are frequently used in business presentations or in the media. But they make it difficult to see trends in the data, and in particular quantitative comparison of data can be quite difficult. In section 14.3.5, we’ll discuss this matter in more detail.
Sometimes we don’t just want to show a single data point, but also want to indicate some range with it. This may be the experimental uncertainty (the errorbar), or it may be the range over which some quantity has changed during the observation interval (this is typical of financial charts). Gnuplot offers several styles that place an indicator for such a range onto the plot. First we’ll look at styles that draw regular errorbars (both in vertical and in horizontal directions). Then we’ll go on to discuss styles that allow us to indicate several ranges at once (but only in the vertical direction).
There are two basic styles to show data with errorbars in gnuplot: errorbars and errorlines. The errorlines style is similar to the linespoints style (a symbol for each data point, adjacent points connected by straight lines), while the errorbars style is similar to the points style (disconnected symbols).
These styles draw errorbars in addition to the actual data. Errorbars can be drawn in either x or y direction, or in both. To select a direction, prefix the style with x, y, or xy respectively, as in set style data xerrorbars or plot “file” with xyerrorlines. Table 5.1 summarizes all available combinations.
Table 5.1. All possible combinations of errorbars and errorlines styles
Errorbars in x direction |
Errorbars in y direction |
Errorbars in both directions |
|
---|---|---|---|
Unconnected symbols |
xerrorbars |
yerrorbars |
xyerrorbars |
Connected symbols |
xerrorlines |
yerrorlines |
xyerrorlines |
Errorbars are drawn in the current line style. A tic mark is placed at the ends of each errorbar (see figure 5.10). The size of the tic mark can be controlled using the set bars option:
Figure 5.10. Different plot styles showing uncertainty in the data. From top to bottom: connected symbols using errorlines, unconnected symbols using errorbars, ranges indicated as boxes using boxxyerrorbars, and finally errors on top of a histogram using boxerrorbars.

The parameter is a multiplier, defaulting to 1.0. The symbolic names small and large stand for the values 0.0 and 1.0, respectively. The value fullwidth is only relevant to histogram styles (more on that in a minute). Finally, the tic marks can be turned off entirely using unset bars.
We must supply additional information to styles with errorbars. Just the x and y coordinates aren’t enough; we must also provide data about the size of the uncertainties. Usually, this data comes from the data file, in the form of one or two additional columns. If one additional column is given, it’s interpreted as a range dy to be added and subtracted from the corresponding data value, so that the errorbar would be drawn from (x, y-dy) to (x, y+dy). If two additional columns are supplied, they are interpreted as the absolute coordinates of the lower and upper end of the errorbar (not the ranges), so that errorbars are drawn from (x, ylow) to (x, yhigh). Corresponding logic applies to errorbars drawn in x direction.
As usual, the columns to use are indicated through the using directive to plot:
Data transformations (see section 3.4 in chapter 3) are often useful in this context. Here are some examples:
- If the input file contains only the variance (instead of the standard deviation, which is usually plotted as error) together with the data, we can apply the necessary square root inline: plot “data” u 1:2:(sqrt($3)) w yerrorb.
- If we know that the uncertainty in the data is a fixed number (such as 0.1), we can supply it directly: plot “data” u 1:2:(0.1) w yerrorl.
- If the data supplied in the file is of the unsupported form (x, y, ylow, yhigh, dx), we can build up the required plot command manually:
plot "data" u 1:2:($1-$5):($1+$5):3:4 w xyerrorl.
As a final style to visualize data with uncertainty in both directions, there’s the boxxyerrorbars style. It’s similar to the xyerrorbars style, except that the range of uncertainty is shown as a rectangular box centered at the data point, rather than as a cross of errorbars.
The last style that uses errorbars is boxerrorbars (not to be confused with boxxyerrorbars), which is a combination of the boxes and yerrorbars styles. It is displayed as a box, with a vertical errorbar centered at its top. It might be used, for instance, for histograms that have some uncertainty in their counting statistics. The additional values required for the errorbar are supplied as the third (or third and fourth) arguments to the using directive. In any case, the box width is provided as the last argument to using.
The styles that we’ve discussed in this section are mostly used to plot data stemming from scientific experiments or calculations, where we want to show the uncertainty in the data clearly. But there are other situations, where we want to indicate a range (or even several ranges) together with the data. Those will be the topic of the next section.
Gnuplot offers two styles that are mostly useful for time series data, although they can be used for other purposes as well: the candlesticks style (also known as bar-and-whiskers plot) and the financebars style. Both have the ability to show two ranges in a single (the vertical) direction, for instance the typical band of variation and the highest and lowest values ever. Both are frequently used for financial data (such as stock prices) and I’ll discuss them in those terms.
Both require five columns of data: the x value, followed (in order) by the opening, low, high, and closing prices. As usual, the appropriate columns are selected through the using directive to the plot command.
Both styles represent the maximum range (low to high) by a vertical line. They differ in the way the secondary (opening to closing) range is displayed: in the candlesticks style, a box of finite width is overlaid the vertical line; in the financebars style, tic marks indicate the opening and closing values. The size of the tic marks is controlled by the set bars option familiar from errorbars styles (see figure 5.11).
Details of the candlesticks can be controlled through some additional options. First of all, if the closing value is greater than the opening one, three vertical lines are drawn inside the box; otherwise, the box is left empty. The width of the box can be changed through the set boxwidth option. (If boxwidth is unset, the value of set bars will be used instead, but this usage is deprecated and should be avoided.) Finally, tic marks can be placed at the ends of the vertical line by appending the keyword whiskerbars (or whisker) to the plot command. The size of these tic marks can be controlled independently from the box width by appending a numerical value to the whiskerbars keyword. This value is interpreted as a multiplier giving the length of the tic mark relative to the box width. Finally, the box will be filled with color or patterns according to the set style fill option.
Neither the financebar nor the candlesticks style connect consecutive entries. If that’s what we want, we’ll have to do so explicitly. Keep in mind that it’s not even clear what should be connected in these styles—they don’t have a concept of a “middle” value. This is why we have to supply a sixth column containing some form of average value, which can then be connected like so: plot “data” u 1:2:3:4:5 w cand, “” u 1:6 w lines.
The candlesticks style in particular is quite versatile and can be used to good effect in a variety of situations.
As of version 4.2, gnuplot has the ability to fill the area between two curves in two-dimensional plots with color or patterns. This is accomplished through the filled-curves style. The appearance of the filled regions is determined by the settings of the fill style, which is controlled by the set style fill option, which we discussed earlier in section 5.2.2.
We need to distinguish between different cases, depending on the nature of the boundaries of the fill region:
- Fill the area between two curves.
- Fill the area between one curve and one straight line (which may be one of the coordinate axes or a plot boundary.
- Treat a single curve as a closed polygon and fill its interior.
- Specify an additional point that will be included when constructing the polygon.
The first case is simple. It requires a data set with at least three columns, corresponding to the x value and the y values for both curves (see figure 5.12):
Figure 5.12. Shading the area between two curves: plot "data" u 1:2:3 w filledcurves. The areas that would be shaded if the above keyword was given are indicated.

This style is only available when plotting data from a file—it can’t be used when plotting functions with gnuplot.
The two lines in this example cross each other, and we can distinguish the enclosed areas depending on whether the first or the second line is greater than (that is, above) the other. In figure 5.12, all enclosed areas are shaded, but we could restrict shading to only one of the two kinds of areas by appending either the keyword above or below. For example, the command plot “data” u 1:2:3 w filledcurves above would shade only the areas indicated in the graph.
Filling the area between a curve and a straight line is more complicated, because we have to specify the location of the straight line, and also have to indicate whether we want to fill on both sides of it or only on one. Figure 5.13 shows both cases. (In all examples in this section, the limiting line is horizontal. The vertical case works in the same way.)
The bottom curve was created using the following:
Here, the bordering straight line is located at y=0 and filling occurs both above and below this line. This is the default. If we want to fill on only one side of the boundary line, we need to indicate this using the keywords above and below. For example, if we had wanted to shade only the areas with positive y values, we could have said plot -cos(x)/(1+0.1*x**2) w filledc above y1=0.
What do we do if we want to fill both above and below certain thresholds for the same curve, as in the middle curve in figure 5.13? The filledcurves style allows for only one limit at a time, but we can help ourselves by overlaying several plots with different locations for the boundary line. The middle curve in figure 5.13 was drawn using the following command:
You can see how we draw the same curve twice, once filling above the upper threshold, and once filling below the lower one. For more complicated shading tasks, we can use user-defined functions that are trimmed (using the ternary operator) where we want the shading to end. The top curve in figure 5.13 was generated this way, using the following:
The first usage is the one we’ve been discussing so far. Note how the limiting value can be given with respect to either the first or the second coordinate system (see chapter 6, section 6.2). Specifying a limiting value for x1 or x2 will lead to a vertical boundary line. The limiting value defaults to zero if not specified otherwise.
The second and third uses treat the curve as a closed polygon (if necessary by connecting the leftmost with the rightmost point of the graph) and attempt to fill its interior. The third use specifies an additional point, which will be included in the polygon. Both of these modes make most sense when used together with parametric plots (see chapter 10, section 10.2.1).
Two styles allow us to encode information by other means than the position on the graph: with labels lets us read a test string from the input file and place it on the plot, and pointsize variable lets us change the symbol size according to the values in the data set.
Let’s look at an example that demonstrates both styles. Listing 5.2 shows a short data file containing the additional information we’ll use for labels and symbol sizes as additional columns. Given this file, we can generate the plot in figure 5.14 using the following commands:
Figure 5.14. Encoding additional information through symbol size or the use of textual labels: pointsize variable and with labels. The corresponding data file is shown in listing 5.2.

Both styles require a third column as part of the using declaration, the contents of which are interpreted as labels or desired symbol sizes, respectively. Variable symbol sizes are most easily recognized if the symbols are circles, which for this terminal setting are chosen by pointtype 6 (or pt 6 for short). Then follows the pointsize variable (abbreviated ps var) specification. Labels are chosen using with labels, and I make sure that all labels are offset a little down and to the right, so that they don’t overlap with any of the circles.
Listing 5.2. Data for figure 5.14
The with labels style in particular is quite versatile and we’ll see some examples that use it in chapter 13. On the other hand, you should exercise some caution when using pointsize variable. For instance, it’s not necessarily clear to the observer whether the radius or the area of the symbol is proportional to the encoded quantity. More generally, it’s not easy to estimate and compare symbol sizes accurately, so that information can easily be lost when encoding it this way. I’ll have more to say about visual perception in chapter 14.
This concludes our overview of styles for regular, two-dimensional xy-plots. We’ll discuss additional styles for surface and contour plots in chapter 8.
The drawing elements for data are lines and points. Lines and points come in different types (such as solid, dashed, and dotted for lines, or square, triangular, and circular for points), and different widths or sizes (respectively). Finally, they may have color. Of course, the specific range of possible selections depends on the terminal, and we can use the test command to see all available choices. For portability reasons, though, two line types are guaranteed to be present in any terminal: the linetype -1 is always a solid line in the primary foreground color (usually black). The linetype 0 is a dotted line in the same color.
Besides the predefined line types that exist for a given terminal, we can form our own customized styles as well. In this section, we look at this possibility, and also take the opportunity to talk about the syntax for style specification in more detail.
To define a new line style, use the set style line command:
The command set style line ... creates a new entry in a sequence of user-defined line styles. The base for each new style is the corresponding system style; only those properties explicitly named in the set style line command are changed.
The linetype and pointtype options refer to the dash pattern for lines and the shape of the symbol used for data points, respectively. Check the test command for your terminal to see the available patterns and symbols.
The linewidth and pointsize options are measured as multipliers relative to the default size. (In other words, the default for both linewidth and pointsize is 1.) Values less than 1 are possible.
The colorspec must be a valid color specification, using any one of the syntax variants described in the following section.
A user-defined combination of linetype, linewidth, pointtype, pointsize, and linecolor (even if many of these properties have default values), created using the set style line command, is referred to as a linestyle, and can be used wherever an individual linetype, linewidth or similar option is expected. For instance, we can use custom line styles in a plot by specifying their index, like so:
Finally, we can make gnuplot switch entirely to using our custom styles. As we’ve seen before, if there is more than one data set, gnuplot cycles through all available plot styles automatically (unless we request a specific style, of course). Usually, gnuplot only uses the predefined styles. However, using the command
we can choose which set of line types to use. The argument default makes gnuplot choose system styles only, while userstyle makes gnuplot choose preferentially from custom styles. I say “preferentially” because gnuplot will fall back to a system style if a custom style isn’t found for some index.
In the previous section, I referred to a colorspec. A colorspec identifies a color in gnuplot. In this section, we look at the syntax for colorspecs.
A colorspec begins with the keyword rgbcolor (or abbreviated rgb), followed by the actual identifier. Three different formats for the identifier are available:
In the first format, we would use an explicit color name, for example rgbcolor "blue". Gnuplot knows 78 distinct colors; you can find a listing of all known color names and their RGB components by issuing this command: show palette colornames.
The second format uses an explicit RGB-triple in hexadecimal representation, preceded by a hashmark. This format is familiar, for instance, from cascading style sheet (CSS) indicators. So, to select blue, we could write rgbcolor "#0000FF" or rgb "#0000ff" (capitalization doesn’t matter).
Finally, rgbcolor variable means that the color is read together with the actual data from the file. This mode is only available for three-dimensional plots generated using the splot command, which we will study in chapter 8. For more details on rgbcolor variable, check the standard gnuplot reference documentation.
Although we won’t make use of this now, I want to mention that there is yet another way to write a colorspec: we can select a color from a continuous spectrum or palette of colors by specifying the position of the color within that spectrum. This allows us to select a color based on the values of the data being plotted, so that we can generate density or other false-color plots. We’ll come back to them in chapter 9.
Let’s look at a quick example that will put many of the topics we’ve just introduced together.
In section 5.2.2 we drew some figures, such as figure 5.7, which contained boxes filled with different fill patterns to help distinguish them from one another. Instead of fill patterns, we can choose to have boxes filled with different fill colors, simply by saying set style fill solid instead of set style fill pattern. But what if we want a solid fill style (that is, no patterns), but need to generate output in black and white (as for this book, for example)?
In such a case, we want to replace the different colors with different shades of gray. We also want gnuplot to choose automatically from all available shades, the way it usually cycles through all available colors or line types.
To achieve this effect, we have to set up a sequence of custom styles, consisting entirely of grayscales. We can then use the set style increment user command to force gnuplot to choose from this collection of custom styles only. Listing 5.3 demonstrates the required commands and figure 5.15 shows the resulting graph.
Figure 5.15. A histogram drawn with custom fill styles—see listing 5.3

Listing 5.3. Defining and using custom styles—see figure 5.15
Let’s step through the commands:
1.
Set up three custom styles (labeled 1, 2, and 3), specifying different shades of gray as line color (lc for short).
2.
Force gnuplot to choose from the custom line styles whenever possible through set style increment user.
3.
Switch to a solid fill style at full saturation (solid 1). This will take the color of each line style and apply it as the fill color.
4.
Also request a border to be drawn around the boxes, using the maximally visible default line type -1 (a solid, black line for almost all terminals).
5.
Draw the histogram as usual.
This example employed several of the techniques we learned in this chapter: custom styles, color specs, fill styles, and histograms. The most important aspect is that you understand how to define your own styles and how to make gnuplot use them whenever possible. This will allow you to tailor the appearance of your graphs to your specific needs (as we did in this example).
This chapter was a bit of an illustrated catalogue: a place where all of gnuplot’s major plot styles are demonstrated by way of an example. As such, I’m not disappointed if you didn’t read the chapter from start to finish: it’s perfectly fine to just look at the figures until you find one that does what you need, and then read the accompanying section.
In the first section, we learned how to choose plot styles (either inline, as part of the plot command, or globally, by fixing the appropriate options with set).
We also introduced the important topic of terminal capabilities early in this chapter: what we can show on a gnuplot-generated graph depends on the capabilities of the output device or terminal. For each possible choice of terminal, we can use the test command to generate a test image that demonstrates the chosen terminal’s capabilities in a standardized fashion.
Everything we did in this chapter is there to visualize data. By contrast, in the next chapter (chapter 6), we look at things we may want to put on a plot in addition to the data: labels, arrows, and other decorations.