On Tue, 25 Mar 2008, Rich Shepard wrote:

  The code's attached, and you can create the same .pdf file I did.

  Helps if I remember to slap it on before sending the message. Here is the
code.

Rich

--
Richard B. Shepard, Ph.D.               |  Integrity            Credibility
Applied Ecosystem Services, Inc.        |            Innovation
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
#!/usr/bin/env python

import os, sys, wx, config
import numpy as nx
from pyx import *
#from numpy import * as nx
from math import *

# Data for a single normal curve:
varData =[(50.0,50.0)]

# Accessory functions
def fwhm2k(fwhm): # for normal and singleton curves
  """
  Converts fwhm value to k (see above)
  """
  return fwhm/(2 * nx.sqrt(nx.log(2)))

def gauss1d(r, fwhm, center):
  """
  Returns the 1d gaussian given by fwhm (full-width at half-max),
  and c (center) at positions given by r
  """
  return nx.exp(-(r-center)**2 / fwhm2k(fwhm)**2)

def boltzman(x, xmid, tau):
  """
  Evaluate the boltzman function with midpoint, xmid, and time constant tau
  over x
  """
  return 1.0 / (1.0 + nx.exp(-(x-xmid)/tau))

# ------------------------------------------------------------------------------

def gaussCurve(midpt, width):
  center = midpt
  fwhm = width
  
  x = nx.arange(0, 100, 0.1)
  G = gauss1d(x, fwhm, center)

  px = graph.axis.painter.regular(titlepos=0.5, titledist= 0.1, labeldist=0.1)
  py = graph.axis.painter.regular(titlepos=0.5, titledist= 0.1, labeldist=0.1,
                                  gridattrs=[style.linestyle.dotted])

  g = graph.graphxy(width=8,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse', painter=px),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)', painter=py),
                    x2=None, y2=None)
  
  g.plot(graph.data.values(x=x, y=G), 
[graph.style.line([style.linewidth.Thin])])

  g.writePDFfile('test1')

"""
# ------------------------------------------------------------------------------

def sCurve(left, right):
  leftend = left
  rightend = right
  midpt = ((rightend-leftend)/2.0) + leftend
  tau = 5.0

  x = nx.arange(leftend, rightend, 0.1)
  S = boltzman(x, midpt, tau)

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'))
  g.plot(x, S)

  g.finish()

# ------------------------------------------------------------------------------

def zCurve(left, right):
  leftend = left
  rightend = right
  midpt = rightend/2.0
  tau = 5.0

  x = nx.arange(leftend, rightend, 0.1)
  Z = 1.0-boltzman(x, midpt, tau)

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'))
  g.plot(x, Z)

  g.finish()

#------------------------------------------------------------------------------

def trapezoidCurve(ll, hl, hr, lr):
  lowLeft = ll
  hiLeft = hl
  hiRight = hr
  lowRight = lr

  x, y = zip(*[(lowLeft, 0.0), (hiLeft, 1.0), (hiRight, 1.0), (lowRight, 0.0)]) 

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'))
  g.plot(x, y)

  g.finish()

# ------------------------------------------------------------------------------
def leftShoulderCurve(hl, hr, lr):
  hiLeft = hl
  hiRight = hr
  lowRight = lr

  x, y = zip(*[(hiLeft, 1.0), (hiRight, 1.0), (lowRight, 0.0)])

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'))
  g.plot(x, y)

  g.finish()

# ------------------------------------------------------------------------------
def rightShoulderCurve(ll, hl, hr):
  lowLeft = ll
  hiLeft = hl
  hiRight = hr

  x, y = zip(*[(lowLeft, 0.0), (hiLeft, 1.0), (hiRight, 1.0)])

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'))
  g.plot(x, y)

  g.finish()
  
# ------------------------------------------------------------------------------
def triangleCurve(ll, cen, lr):
  lowLeft = ll
  center = cen
  lowRight = lr

  x, y = zip(*[(lowLeft, 0.0), (center, 1.0), (lowRight, 0.0)])

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'))
  g.plot(x, y)

  g.finish()

# ------------------------------------------------------------------------------
def singletonCurve(cen, width):
  center = cen
  fwhm = width

  x = nx.arange(0, 100, 0.1)
  S = gauss1d(x, fwhm, center)

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'))
  g.plot(x, y)
# ------------------------------------------------------------------------------
def betaCurve(cen, inflPt, width):
  pass

# ------------------------------------------------------------------------------
def dataCurve(ptList):
  pass

# ------------------------------------------------------------------------------
def rectangleCurve(ll, hl, hr, lr):
  pass
# ------------------------------------------------------------------------------
def linearIncrCurve(ll, hr):
  lowLeft = ll
  highRight = hr

  x, y = zip(*[(lowLeft, 0.0), (highRight, 1.0)])

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'))
  g.plot(x, y)

  g.finish()
  
# ------------------------------------------------------------------------------
def linearDecrCurve(hl, lr):
  highLeft = hl
  lowRight = lr

  x, y = zip(*[(highLeft, 1.0), (lowRight, 0.0)])

  p = graph.axis.painter.regular(titlepos=0.3, titledirection=None)

  g = graph.graphxy(width=8, x2=None, y2=None,
                    x=graph.axis.linear(min=0, max=100, title='Universe of 
Discourse'),
                    y=graph.axis.linear(min=0.0, max=1.0, title='Membership 
Grade ($\mu$)'),
                    painter=p)
  g.plot(x, y)

  g.finish()

# ------------------------------------------------------------------------------
def outcomeCurve():
  pass

# EOF functions
"""

if __name__ == "__main__":
  gaussCurve(50.0, 35.0)

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to