Package nltk :: Package draw :: Module plot :: Class Plot
[hide private]
[frames] | no frames]

Class Plot

source code

object --+
         |
        Plot

A simple graphical tool for plotting functions. Each new Plot object opens a new window, containing the plot for a sinlge function. Multiple plots in the same window are not (yet) supported. The Plot constructor supports several mechanisms for defining the set of points to plot.

Example plots

Plot the math.sin function over the range [-10:10:.1]:

>>> import math
>>> Plot(math.sin)

Plot the math.sin function over the range [0:1:.001]:

>>> Plot(math.sin, slice(0, 1, .001))

Plot a list of points:

>>> points = ([1,1], [3,8], [5,3], [6,12], [1,24])
>>> Plot(points)

Plot a list of values, at x=0, x=1, x=2, ..., x=n:

>>> Plot(x**2 for x in range(20))
Instance Methods [hide private]
 
__init__(self, vals, rng=None, **kwargs)
Create a new Plot.
source code
 
_init_bindings(self, parent) source code
 
_init_menubar(self, parent) source code
 
_log(self, *e) source code
 
about(self, *e)
Dispaly an 'about' dialog window for the NLTK plot tool.
source code
 
help(self, *e)
Display a help window.
source code
 
postscript(self, *e)
Print the (currently visible) contents of the plot window to a postscript file.
source code
 
destroy(self, *args)
Cloase the plot window.
source code
 
mainloop(self, *varargs, **kwargs)
Enter the mainloop for the window.
source code
 
_zoom(self, i1, j1, i2, j2) source code
 
_zoom_in_buttonpress(self, event) source code
 
_zoom_in_drag(self, event) source code
 
_zoom_in_buttonrelease(self, event) source code
 
_zoom_in(self, *e) source code
 
_zoom_out(self, *e) source code
 
_zoom_all(self, *e) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, vals, rng=None, **kwargs)
(Constructor)

source code 

Create a new Plot.

Parameters:
  • vals - The set of values to plot. vals can be a list of y-values; a list of points; or a function.
  • rng - The range over which to plot. rng can be a list of x-values, or a slice object. If no range is specified, a default range will be used. Note that rng may not be specified if vals is a list of points.
  • scale - The scales that should be used for the axes. Possible values are:
    • 'linear': both axes are linear.
    • 'log-linear': The x axis is logarithmic; and the y axis is linear.
    • 'linear-log': The x axis is linear; and the y axis is logarithmic.
    • 'log': Both axes are logarithmic.

    By default, scale is 'linear'.

Overrides: object.__init__

mainloop(self, *varargs, **kwargs)

source code 

Enter the mainloop for the window. This method must be called if a Plot is constructed from a non-interactive Python program (e.g., from a script); otherwise, the plot window will close as soon se the script completes.