[PYTHON MATRIX-SIG] Matrix Plot module (small announcement)

Thomas Schwaller et@appl-math.tu-muenchen.de
Mon, 20 Nov 1995 16:07:08 +0100

Hi folks,
I promised to rewrite the plmodule for use with the matrixmodule.
The next message will contain the first test version of the module. This one
contains a test script and 'HOW TO BUILD' remarks. Trivial for most of us,
but nevertheless...

GENERAL REMARKS on plplot: (read also plmodule.c)

PlPlot is certainly not the last word on Plotting (somebody should
do an OpenGL plotting module!), but as a starting point it might be useful.
I like it because it has a Tk widget with it.

John Interrante and myself wrote it as the same time but he will not support it
anymore, that's why I am doing this job... :-)
I put both distributions together, but this new version is a really a new
All List inputs are now replaced by matrix inputs (Not backward compatible !)
Could have made boths inputs (matrix and python lists ) possible, but matrix
input is much faster and is the first choice here (MatLab style), so why people
should use the slower lists instead?
Further I added __doc__ strings everywhere (this where the previous C-comments
available now with python! :-))
The Input is not realy tested. At the moment it assumes that you are doing the
right thing. Comments are welcome here...
I hope I well get feedback from people using that module (which was done
quite fast, but I don't want let you wait! :-))
Send me as much scripts using that stuff (perhaps some Matlab alike procedures)
I some people want to do the missing things, you are welcome.
Mai place will be ftp://ftp.appl-math.tu-muenchen.de/pub/et/plmodule.tgz

Enjoy it...



1) PLplot is available by anonymous ftp from dino.ph.utexas.edu in the
   plplot/ directory.
2) Install plplot (configure it with double precision and tk support)
   You will get a libplplotdtk.a (or build a shared library)
3) Rebuid python with Tk and add

   extern int Pltk_Init(Tcl_Interp*);

   if (Pltk_Init(interp) == TCL_ERROR)
     return TCL_ERROR;

   in tkappinit.c and

   add -lplplotdtk (+ perhaps appropriate path) in Setup at
   the right place.

3a) Build the plmodule as shared library or as built in module.

4) Add the following to your TKinter.py

class PLWin(Widget):
	def __init__(self, master=None, cnf={}, **kw):
		Widget.__init__(self, master, 'plframe', cnf, kw)

class PLXWin(Widget):
	def __init__(self, master=None, cnf={}, **kw):
		Widget.__init__(self, master, 'PLXWin', cnf, kw)

#! /usr/local/bin/python

from pl import *
from Matrix import *
from Tkinter import *

class Test:
  def plot0(self):
    plvpor(0.0, 1.0, 0.0, 1.0)
    plwind(0.0, 1.0, 0.0, 1.0)
    plbox("bc", 0.0, 0, "bc", 0.0, 0)
    plsvpa(50.0, 150.0, 100.0, 150.0)
    plwind(0.0, 1.0, 0.0, 1.0)
    plbox("bc", 0.0, 0, "bc", 0.0, 0)
    plptex(0.5, 0.5, 1.0, 0.0, 0.5, "BOX at (50,150,100,150)")

  def plot1(self):
    x = mrange(0.1, 6.1, 0.1)
    y = pow(x, 2)
    xs1 = zeros(6)
    ys1 = zeros(6)
    xmin, xmax = x[0], x[59]
    ymin, ymax = y[0], y[59]
    for i in range(6):
      xs1[i] = x[i * 10 + 3]
      ys1[i] = y[i * 10 + 3]
    plenv(xmin, xmax, ymin, ymax, 0, 0)
    pllab("(x)", "(y)", "#frPlot Example 1 : y=x#u2")
    plpoin(xs1, ys1, 10)
    plline(x, y)

  def plot2(self):
    plenv(0.0, 2*pi, -1.0, 1.0, 0, 1)
    pllab("(x)", "sin(x)", "#frPlot Example 2 : Sin Function")
    x = mrange(0, 2*pi, 2*pi/500)
    plline(x, sin(x))

  def plot5(self):
    n = 2047
    data = sin(mrange(0, 2*pi, 2*pi/n))
    plhist(data, -1.1, 1.1, 44, 0)
    pllab("#frValue", "#frFrequency", "#frPlot Example 5 : Probability function
of Oscillator")

  def plot8(self):
    m, n  =  35, 46
    x=mrange(-1, 1, 2.0/m)
    y=mrange(-1, 1, 2.0/n)
    r=sqrt(add.outer(x*x, y*y))
    plvpor(0.0, 1.0, 0.0, 0.9)
    plwind(-1.0, 1.0, -0.9, 1.1)
    plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 60.0, 120)
    plbox3('bnstu', 'x axis', 0.0, 0, 'bnstu', 'y axis', 0.0, 0, 'bcdmnstuv',
'z axis', 0.0, 0)
    plplot3d(x, y, z, 3, 0)
    plmtex('t', 1.0, 0.5, 0.5, '#frPlot Example 8 : Alt=60, Az=120')

  def plot9(self):
    mypltr = lambda x, y: (2.0/34 * x -1.0, 2.0/34 * y -1.0)
    nx, ny  =  35, 46
    mark, space = 1500, 1500
    clevel = Matrix(-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0)
    x=mrange(-1, 1, 2.0/nx)
    y=mrange(-1, 1, 2.0/ny)-1.0
    z=subtract.outer(x*x, y*y)
    w=multiply.outer(2*x, y)
    plenv(-1.0, 1.0, -1.0, 1.0, 0, 0)
    plcont(z, 1, nx, 1, ny, clevel, mypltr)
    plstyl(1, mark, space)
    plcont(w, 1, nx, 1, ny, clevel, mypltr)
    plstyl(0, mark, space)
    pllab("X Coordinate", "Y Coordinate", "Streamlines of flow")

  def makePlotMenu(self, mBar):
    Plot = Menubutton(mBar, text='Plot', underline='0')
    Plot.pack(side='left', padx='2m')
    Plot.menu = Menu(Plot)
    Plot.menu.add('command', label='Example0', command=self.plot0)
    Plot.menu.add('command', label='Example1', command=self.plot1)
    Plot.menu.add('command', label='Example2', command=self.plot2)
    #Plot.menu.add('command', label='Example3', command=self.plot3)
    Plot.menu.add('command', label='Example5', command=self.plot5)
    Plot.menu.add('command', label='Example8', command=self.plot8)
    Plot.menu.add('command', label='Example9', command=self.plot9)
    Plot.menu.add('command', label='Quit', underline='0', background='red',
			           activebackground='green', command='exit')
    Plot['menu'] = Plot.menu
    return Plot

  def __init__(self, master, width=550, height=412, bg='black',
    self.mBar = Frame(master, relief=relief, bd='2')
    self.mBar.pack(side='top', fill='x')
    self.Plot = self.makePlotMenu(self.mBar)
    self.glx = PLWin(master, width=`width`, height=`height`, bg=bg)
    self.QUIT = Button(master, text='QUIT', fg='red', command=master.quit,
    self.QUIT.pack(side='bottom', fill='both')

if __name__ == '__main__':
	test = Test(root, 600, 600, 'black', 'raised')

MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org