3.2 First plots
The core graphplotting command of Pyxplot is the plot command. The following simple example plots the trigonometric function :
plot sin(x)
This is one of a large number of standard mathematical functions which are built into Pyxplot; a complete alphabetical list of them can be found in Chapter 12.
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 data file, and the coordinate from the second. The data file is assumed to be in plain text format, with columns separated by whitespace and/or commas:
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)
Pyxplot supports almost all of the same mathematical operators as the C programming language; a complete list of them can be found in Table 3.1. If you have experience of similar tricks in C, it is quite possible to write the following expressions in Pyxplot (but don’t worry if this is a little over your head):
pyxplot> print (a=3)+(b=2)
5
pyxplot> print a0?"yes":"no"
yes
pyxplot> print "%s %s"%(++a,b++)
4 2
pyxplot> print (a+=10 , b+=10 , a+b)
27
In the final example, the comma operator is used as in C, to return only the value of the final commaseparated expression.
Symbol 
Description 
Operator Associativity 
** 
Algebraic exponentiation 
righttoleft 
 
Unary minus sign 
righttoleft 
– 
Unary decrement 
righttoleft 
+ 
Unary plus sign 
righttoleft 
++ 
Unary increment 
righttoleft 
not ! 
Logical not 
righttoleft 

Unary one’s complement 
righttoleft 
* 
Algebraic multiplication 
lefttoright 
/ 
Algebraic division 
lefttoright 
% 
Modulo operator 
lefttoright 
+ 
Algebraic sum 
lefttoright 
 
Algebraic subtraction 
lefttoright 
<< 
Left binary shift 
lefttoright 
>> 
Right binary shift 
lefttoright 
< 
Magnitude comparison 
righttoleft 
> 
Magnitude comparison 
righttoleft 
<= 
Magnitude comparison 
righttoleft 
>= 
Magnitude comparison 
righttoleft 
== <> 
Equality comparison 
righttoleft 
!= 
Equality comparison 
righttoleft 
& 
Binary and 
lefttoright 

Binary exclusive or 
lefttoright 
 
Binary or 
lefttoright 
and && 
Logical and 
lefttoright 
or  
Logical or 
lefttoright 
?: 
Ternary conditional 
righttoleft 
= 
Assignment operator 
righttoleft 
+= = *= 
Assignment operators 
righttoleft 
/= %= &= 


= = 


<<= >>= 


, 
Comma separator 
lefttoright 
Table 3.1: A list of mathematical operators which Pyxplot recognises, in order of descending precedence. Items separated by horizontal rules are of differing precedence; those not separated by horizontal rules are of equal precedence. The third column indicates whether strings of operators are evaluated from left to right, or from right to left. For example, the expression x**y**z is evaluated as (x**(y**z)).