2.2 First Plots

The basic workhorse command of PyXPlot is the plot command, which is used to produce all plots. The following simple example would plot the function $\sin (x)$:

plot sin(x)

It is also possible to plot data stored in files on disk. The following would plot data from a file data.dat, taking the $x$-co-ordinate of each point from the first column of the data file, and the $y$-co-ordinate from the second. The data file is assumed to be in plain text format1, with columns separated by whitespace and/or commas2:

plot 'data.dat'

Several items can be plotted on the same graph by separating them by commas:

plot 'data.dat', sin(x), cos(x)

It is possible to define one’s own variables and functions, and then plot them:

a = 2
b = 1
c = 1.5
f(x) = a*(x**2) + b*x + c
plot f(x)

To unset a variable or function once it has been set, the following syntax should be used:

a =
f(x) =

Footnotes

  1. If the filename of a data file ends with a .gz suffix, it is assuming to be gzipped plaintext, and is decoded accordingly.
  2. This format is compatible with the Comma Separated Values (CSV) format produced by many applications, including Microsoft Excel.