I have three unresolved issues in the attached code, and I'd like to
resolve the first two on this thread. (The third issue relates to plotting
using only the left and bottom axes rather than a complete frame.)

  Issue #1: I am apparently not properly closing/clearing a plot. There are
three plots in the test data set, and when the last one (with three curves
on a common set of axes) is the only one plotted, it is correctly done. But,
when it follows the 2-curve plots, they are also displayed.

  I probably am turning .hold() off and on in the wrong places, but I don't
know where the right places are. On a side note, if I try to use plot.hold()
to toggle the hold state off python throws an error. I need to explicitly
use plot.hold(False).

  Issue #2: Is there a way to define the parameters for the Gaussian curve
so the end points are actually 0.0 on the y axis while the mid point is as
specified?

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, config, testFunctions
import matplotlib
import matplotlib.numerix as nx
import pylab


varData =[("Low","Variety","Fish","Wildlife","Decay 
S-Curve",1,0.0,100.0,0.0,100.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("High","Variety","Fish","Wildlife","Growth 
S-Curve",2,0.0,100.0,0.0,100.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("Low","Variety","Terrestrial","Wildlife","Decay 
S-Curve",1,0.0,100.0,0.0,100.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("High","Variety","Terrestrial","Wildlife","Growth 
S-Curve",2,0.0,100.0,0.0,100.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("Low","HabitatComplexity","Fish","Wildlife","Decay 
S-Curve",1,0.0,100.0,0.0,100.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("High","HabitatComplexity","Fish","Wildlife","Growth 
S-Curve",2,0.0,100.0,0.0,100.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("Low","HabitatComplexity","Terrestrial","Wildlife","Decay 
S-Curve",1,0.0,100.0,0.0,100.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("High","HabitatComplexity","Terrestrial","Wildlife","Growth 
S-Curve",2,0.0,100.0,0.0,100.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("Low","SpecialConcern","Fish","Wildlife","Decay 
S-Curve",1,0.0,100.0,0.0,50.0,0.0,50.0,50.0,0.0,50.0,1.0,3),
("Moderate","SpecialConcern","Fish","Wildlife","Bell 
Curve",2,0.0,100.0,0.0,100.0,0.0,50.0,50.0,50.0,50.0,1.0,3),
("Many","SpecialConcern","Fish","Wildlife","Growth 
S-Curve",3,50.0,100.0,50.0,50.0,0.0,100.0,50.0,100.0,50.0,1.0,3)]

def testCode():
  for row in varData:
    curComp = row[3]
    curSub = row[2]
    curVar = row[1]
    
    plotting = True

    if plotting:
      pylab.hold(True)
      if row[4] == 'Decay S-Curve':
        testFunctions.zCurve(row[10],row[9])
      elif row[4] == 'Bell Curve':
        testFunctions.gaussCurve(row[13],row[14])
      elif row[4] == 'Growth S-Curve':
        testFunctions.sCurve(row[8],row[11])
      elif row[4] == 'Beta':
        testFunctions.betaCurve(row[13],row[12],row[14])
      elif row[4] == 'Data':
        continue
      elif row[4] == 'Linear Increasing':
        testFunctions.linearIncrCurve(row[8],row[11])
      elif row[4] == 'Linear Decreasing':
        testFunctions.linearDecrCurve(row[10],row[9])
      elif row[4] == 'Left Shoulder':
        testFunctions.leftShoulderCurve(row[10],row[11],row[9])
      elif row[4] == 'Trapezoid':
        testFunctions.trapezoidCurve(row[8],row[10],row[11],row[9])
      elif row[4] == 'Right Shoulder':
        testFunctions.rightShoulderCurve(row[8],row[10],row[11])
      elif row[4] == 'Triangle':
        testFunctions.triangleCurve(row[8],row[13],row[9])
      elif row[4] == 'Singleton':
        testFunctions.singletonCurve(row[13],row[14])
      elif row[4] == 'Rectangle':
        testFunctions.rectangleCurve(row[8],row[10],row[11],row[9])
      elif row[4] == 'Outcome':
        testFunctions.outcomeCurve()

    if row[5] == row[16]:
      pylab.savefig(curVar+'_'+curSub+'_'+curComp+'.png')
      pylab.hold(False)
      plotting = False
      
if __name__ == "__main__":
  testCode()
#!/usr/bin/env python

import os, sys, wx, config
import matplotlib
import matplotlib.numerix as nx
import pylab as p

from numpy import linalg
from math import *
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure

matplotlib.interactive(False)

def fwhm2k(fwhm): # for matplotlib Gaussian 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)
  """
  if self.graphstate == 1:
    self.graph.Destroy()
  self.graph = functions.PlotPanel(self.pplot, x, G)
  self.graphstate = 1
  """
  p.plot(x, G, color='blue', lw=1)
  p.axis([0, 100, 0.0, 1.0])
  p.xlabel('Universe of Discourse')
  p.ylabel('Membership Grade')
  #p.show()

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

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.plot(x, S, color='red', lw=1)
  p.axis([0, 100, 0.0, 1.0])
  #p.axhline(linewidth=1, color='black')
  #p.axvline(linewidth=1, color='black')
  p.xlabel('Universe of Discourse')
  p.ylabel('Membership Grade')

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

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.plot(x, Z, color='red', lw=1)
  #p.box(on=False)
  p.axis([0, 100, 0.0, 1.0])
  #p.axhline(linewidth=1, color='black')
  #p.axvline(linewidth=1, color='black')
  p.xlabel('Universe of Discourse')
  p.ylabel('Membership Grade')

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

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.plot(x, y, color='red', lw=1)
  p.axis([0, 100, 0.0, 1.0])
  p.xlabel('Universe of Discourse')
  p.ylabel('Membership Grade')
  #p.show()
# ------------------------------------------------------------------------------
def leftShoulderCurve(hl, hr, lr):
  hiLeft = hl
  hiRight = hr
  lowRight = lr

  x, y = zip(*[(hiLeft, 1.0), (hiRight, 1.0), (lowRight, 0.0)]) 
  p.plot(x, y, color='red', lw=1)
  p.axis([0, 100, 0.0, 1.0])
  p.xlabel('Universe of Discourse')
  p.ylabel('Membership Grade')
  #p.show()

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

  x, y = zip(*[(lowLeft, 0.0), (hiLeft, 1.0), (hiRight, 1.0)]) 
  p.plot(x, y, color='red', lw=1)
  p.axis([0, 100, 0.0, 1.0])
  p.xlabel('Universe of Discourse')
  p.ylabel('Membership Grade')
  #p.show()

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

  x, y = zip(*[(lowLeft, 0.0), (center, 1.0), (lowRight, 0.0)]) 
  p.plot(x, y, color='red', lw=1)
  p.axis([0, 100, 0.0, 1.0])
  p.xlabel('Universe of Discourse')
  p.ylabel('Membership Grade')
  #p.show()

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

  x = nx.arange(0, 100, 0.1)
  S = gauss1d(x, fwhm, center)
  p.plot(x, S, color='red', lw=1)
  p.axis([0, 100, 0.0, 1.0])
  p.xlabel('Universe of Discourse')
  p.ylabel('Membership Grade')
  #p.show()
  
# ------------------------------------------------------------------------------
def betaCurve(cen, inflPt, width):
  pass

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

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

# ------------------------------------------------------------------------------
def linearDecrCurve(hl, lr):
  pass

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

# EOF functions  
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to