The basic workhorse command of PyXPlot is the plot command, which is used to produce all plots. The following simple example would plot the trigonometric function :
plot sin(x)
This is one of a large number of standard mathematical functions which are built into PyXPlot. We will meet more of these in due course, but a complete list can be found in Appendix 2.
As well as plotting functions, it is also possible to plot data stored in files. The following would plot data from a file data.dat, taking the -coordinate of each point from the first column of the datafile, and the
-coordinate from the second. The datafile 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, as in
plot 'data.dat', sin(x), cos(x)
and it is possible to define one’s own variables and functions, and then plot them, as in the example
a = 0.02 b = -1 c = 5 f(x) = a*(x**3) + b*x + c plot f(x)
A complete list of the mathematical operators which can be used to put together algebraic expressions can be found in Table 3.1.
Symbol |
Description |
Operator Associativity |
** |
Algebraic exponentiation |
right |
- |
Unary minus sign |
left |
not |
Logical not |
left |
* |
Algebraic multiplication |
left |
/ |
Algebraic division |
left |
% |
Modulo operator |
left |
+ |
Algebraic sum |
left |
- |
Algebraic subtraction |
left |
<< |
Left binary shift |
left |
>> |
Right binary shift |
left |
< |
Magnitude comparison |
right |
> |
Magnitude comparison |
right |
<= |
Magnitude comparison |
right |
>= |
Magnitude comparison |
right |
== |
Equality comparison |
right |
!= |
Equality comparison |
right |
<> |
Alias for != |
right |
& |
Binary and |
left |
|
Binary exclusive or |
left |
| |
Binary or |
left |
and |
Logical and |
left |
or |
Logical or |
left |
Footnotes