Extending Plotter

How Functions Are Evaluated

A Plotter function is just a Python expression that evalutes to give either a single number (for cartesian and polar functions) or a tuple of two numbers (for parametric functions) for each input value. Every time Plotter needs to evaluate a function, it does so in a common user namespace. This means that you can define your own Python functions, variables, and even classes and produce plots from them.

Python Console

The Console menu item pops up a console which will execute Python code interactivly in Plotter's user namespace. You can use the console to define Python functions and variables that you want to be accessible from your Plotter functions, and to control all aspects of Plotter using the plotter interface functions.

Setup Code

The setup code that is defined in the options dialog box is executed in the user namespace before any of the functions to be plotted are evaluated - this gives you a chance to import any modules that you want to plot from, define functions etc. By default, the math and plotter modules are imported to give you access to Python's mathematical functions and to the Plotter control functions. Setup code is saved when you save a file, and executed when you load one.

Writing Your Own Scripts

If you save a file from Plotter and look at it an a text editor, you will see that it is just a simple Python script that calls the Plotter interface code imported from the plotter module to do things like setting the axes and plotting functions. So, to extend Plotter, you can just edit and add to these scripts.

Plotter Interface Module

The plotter module provides the interface between user scripts and the Plotter application. It's functions allow you to control all aspects of Plotter in an extensible way. This module is imported by default into all scripts saved from Plotter, and it is what is used to load and save sets of graphs.

Function Operations

plot(function, [colour, [doredraw]])
This is the main interface for plotting functions. function should be a string e.g. 'y = sin(x)', 'r = 3*sin(3*t)' or 'x, y = sin(t), cos(t)'.

colour is a string describing the colour to be used to plot this function: either a descriptive name such as 'red', or a hexadecimal triplet of the form '#rrrrggggbbbb'. If no colour is specified, then red is used.

doredraw is a boolean argument specifying whether the graph should be redrawn. The default is true, so this parameter can generally be omitted.

Adds a new blank function to Plotters function list.
Remove the currently selected function from the function list, or the last function if there is no selected function.

Remove the currently selected function from the function list, or the last function if there is no selected function.

Window Operations

Open a new Plotter window
Close the current Plotter window

File Operations

Popup the save dialog box.
Save the current Plotter window to the file filename.
Load the file filename and execute the commands that it contains.

View Operations

Zoom the display in the current window by factor.
Centre the display in the current window.
pan(dx, dy)
Translate the display in the current window by the vector (dx, dy).
Redraw the axes and replot all functions in the current window.
Set the visibility of the grid. This function redraws the display after the change has been made.
set_x_axis(min, max, pitch, [axis, [ticks, [labels]]])
Specify the min, max and pitch (interval between tick-marks) for the x-axis - these should all be floating point numbers, with min less than max. Optionally, the last three boolean arguments set the visibility of the axis, tick-marks and labels. This function redraws the display after the changes have been made.
set_y_axis(min, max, pitch, [axis, [ticks, [labels]]])
As above, but for the y-axis.
set_t(min, max, number)
Specify the range of t values used when plotting parametric and polar functions. number is the number of points to plot for each function. This function redraws the display after the changes have been made.

Dialog Boxes

Display the Plotter options dialog box.
Open a Python console for the current window.
Display the Plotter help directory.

Plotter 0.2.1 Documentation
James Kermode, August 2001