3.3.5 General Extensions Beyond Gnuplot

plot linewidths

For an unknown reason, gnuplot doesn’t allow set linewidth 2 as valid syntax. This setting is permitted in PyXPlot. Furthermore, set pointlinewidth 2 will set the linewidth to be used when drawing data points. A similar effect can be achieved via:

plot sin(x) with points pointlinewidth 2

In both cases, the abbreviation plw is valid.

dots plot style

When using the dots style, for example:

plot sin(x) with dots

the size of the plotted dots can be varied with the pointsize modifier, unlike in gnuplot, where the dots were of a fixed size. For example, to display big dots, use:

plot sin(x) with dots pointsize 10

select keyword

As well as the index, using and every keywords which gnuplot used to allow users to plot subsets of data from datafiles, PyXPlot also has a further modifier, select. This can be used to plot only those datapoints in a datafile which specify some given criterion. For example:

plot 'datafile' select ($8>5)
plot sin(x) select (($1>0) and ($2>0))
   

In the second example, two select criteria are given, combined with the logical and operatorSee Table 2.2 for a list of all operators recognised by PyXPlot.. The select modifier has many applications, including plotting two-dimensional slices from three-dimensional datasets, and selecting certain subsets of datapoints from a datafile for plotting.

   

Logical operators such as and, or and not can be used, as seen in the second example above; indeed, any expression which is valid Python can be used.

arrows plot style

The arrows plot style takes four columns of data, $x_1$, $y_1$, $x_2$, $y_2$, and for each data point draws an arrow from the point $(x_1,y_1)$ to $(x_2,y_2)$. Three different kinds of arrows can be drawn: ones with normal arrow heads, ones with no arrow heads, which just appear as lines, and ones with arrow heads on both ends. The syntax is:

plot 'datafile' with arrows_head
plot 'datafile' with arrows_nohead
plot 'datafile' with arrows_twohead
   

The syntax ‘with arrows’ is a shorthand for ‘with arrows_head’.

lower and upper limit datapoints

PyXPlot can plot datapoints using the standard upper- and lower-limit symbols. No special syntax is required for this; these symbols are pointtypesThe pointtype modifier was introduced in Section 2.7. 12 and 13 respectively, obtained as follows:

plot 'upperlimits' with points pointtype 12
plot 'lowerlimits' with points pointtype 13

plotting functions with errorbars and other plot styles

In gnuplot, when a function (as opposed to a datafile) is plotted, only those plot styles which accept two columns of data can be used – for example, lines or points. It is not possible to plot a function with errorbars, for example. In PyXPlot, by contrast, this is possible using the following syntax:

plot f(x):g(x) with yerrorbars
   

Two functions are supplied, separated by a colon; plotting proceeds as if a datafile had been supplied, containing values of $x$ in column 1, values of $f(x)$ in column 2, and values of $g(x)$ in column 3. This may be useful, for example, if $g(x)$ measures the intrinsic uncertainty in $f(x)$. The using modifier may also be used:

plot f(x):g(x) using 2:3
   

Here, $g(x)$ would be plotted on the $y$-axis, against $f(x)$ on the $x$-axis. It should be noted, however, that the range of values of $x$ used would still correspond to the range of the plot’s horizontal axis. If the above were to be attempted with an autoscaling horizontal axis, the result might be rather unexpected – PyXPlot would find itself autoscaling the $x$-axis range to the spread of values of $f(x)$, but find that this itself changed depending upon the range of the $x$-axis.

horizontally arranged datafiles

The command syntax for plotting columns of datafiles against one another was previously described in Section 2.5. In an extension of gnuplot’s interface, it is also possible to plot rows of data against one another in horizontally-arranged datafiles. For this, the keyword ‘rows’ is placed after the using modifier:

plot 'datafile' index 1 using rows 1:2
   

The syntax ‘using columns’ is also accepted, to specify the default behaviour of plotting columns against one another:

plot 'datafile' index 1 using columns 1:2
   

When plotting horizontally-arranged datafiles, the meanings of the index and every modifiers (see Section 2.5) are altered slightly. The former continues to refer to vertical blocks of data separated by two blank lines. Blocks, as referenced in the every modifier, continue to be vertical blocks of datapoints, separated by single blank lines. The row numbers passed to the using modifier are counted from the top of the current block.

   

However, the line-numbers specified in the every modifier – i.e. variables $a$, $c$ and $e$ in the system above – now refer to horizontal columns, rather than lines. For example:

   
plot 'datafile' using rows 1:2 every 2::3::9
   

would plot the data in row 2 against that in row 1, using only the values in every other column, between columns 3 and 9.

errorbars

In gnuplot, when one used errorbars, one could either specify the size of the errorbar, or the min/max range of the errorbar. Both of these usages shared a common syntax, and gnuplot’s behaviour depended upon the number of data columns provided:

plot 'datafile' with yerrorbars
   

Given a datafile with three columns, this would take the third column to indicate the size of the $y$-errorbar, and given a four-column datafile, it would take the third and fourth columns to indicate the min/max range to be marked out by the errorbar.

   

To avoid confusion, a different syntax is adopted in PyXPlot. The syntax:

plot 'datafile' with yerrorbars
   

now always assumes the third column of the datafile to indicate the size of the errorbar, regardless of whether a fourth is present. The syntax:

plot 'datafile' with yerrorrange
   

always assumes the third and fourth columns to indicate the min/max range of the errorbar.

For clarity, a complete list of errorbar styles is given below:

   

yerrorbars

Vertical errorbars; size drawn from the third data-column.

xerrorbars

Horizontal errorbars; size drawn from the third data-column.

xyerrorbars

Horizontal and vertical errorbars; sizes drawn from the third and fourth data-columns respectively.

errorbars

Shorthand for yerrorbars.

   

yerrorrange

Vertical errorbars; minimum drawn from the third data-column, maximum from the fourth.

xerrorrange

Horizontal errorbars; minimum drawn from the third data-column, maximum from the fourth.

xyerrorrange

Horizontal and vertical errorbars; horizontal minimum drawn from the third data-column, and maximum from the fourth; vertical minimum drawn from the fifth, and maximum from the sixth.

errorrange

Shorthand for yerrorrange.

datafile wildcards

PyXPlot allows the wildcards ‘*’ and ‘?’ to be used both in the filenames of datafiles following the plot command, and also when specifying command files on the command line and with the load command. For example, the following would plot all datafiles in the current directory with a ‘.dat’ suffix, using the same plot options:

   
plot '*.dat' with linewidth 2

In the legend, full filenames are displayed, allowing the datafiles to be distinguished.

   

As in gnuplot, a blank filename passed to the plot command causes the last used datafile to be used again.

backing up overwritten files

By default, when plotting to a file, if the output filename matches that of an existing file, that file is overwritten. This behaviour may be changed with the set backup command, which has syntax:

   
set backup
set nobackup
   

When this switch is turned on, pre-existing files will be renamed with a tilde at the end of their filenames, rather than being overwritten.