Plotting data like measurement results is probably the most used method of plotting in gnuplot. It works basically like the plotting of functions. But in this case we need a data file and some commands to manipulate the data. First, we will start with the basic plotting of simple data and thereafter look at the plotting of data with errors.

Simple data

At first we will have a look at a data file. This can be a text file containing the datapoints as columns.

As you can see, we have added another color and point type and plotted the two datasets by using index and separated the plots by a comma. To reuse the last filename we can just type ''. The result is shown in Fig. 3.

Data with errors

Another common task is to plot data with errorbars. Therefore we use the battery.dat file from gnuplots demo files that contains data about the dependence of the power of the battery on the resistance.
Here we want not only to plot the data, but also show the error for the y value (the data is stored in the format: x, y, xerror, yerror).

The power values are stored in Watt in the data file, but only has values lower than 1. That’s why we want to use mW as unit. Therefore we set the format option to tell gnuplot to use “mantissa to base of current logscale”, see gnuplot’s documentation. Then in the plot command using tells gnuplot which columns from the data file it should use. Since we want to plot the y errors and the data we need three columns in the first line of the plot command. Using the yerrorbars plotting style it is not possible to combine the points by a line. Therefore we add a second line to the plot command to combine the points with a line. This will give us the resulting Fig. 4.

Generally the legend is enabled by the set key command. In addition to that, its position can be specified by set key top left etc. You can also set it directly to one point as we have done it here in order to have enough space between the key and the tics. The title keyword within the plot command specifies the text to be displayed in the legend.