## Re: [PyX-user] PyX For Curve Plotting?

 Re: [PyX-user] PyX For Curve Plotting? From: Rich Shepard - 2008-03-23 17:50:43 ```On Thu, 20 Mar 2008, Alan G Isaac wrote: > Please note that there are great differences between the two applications. > PyX is a PostScript oriented drawing and plotting application; Matplotlib > provides interactive graphics. Also, note that PyX is under the GPL. Alan, Let me start over with the PyX group. Matplotlib does non-interactive, publication-quality plots, too. But, it is derived from MatLab and has serious limitations as far as my needs are concerned. Allow me to share what I'm trying to do, then folks can point me toward the appropriate part(s) of the manual and faq to learn how to do it. These are some of the functions I need to plot in my application. The last part of each (starting with 'p.' is the mpl code that would, I presume, be replaced by pyx code: 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) p.plot(x, G, color='red', lw=1) p.axis([0, 100, 0.0, 1.0]) p.xlabel('Universe of Discourse') p.ylabel('Membership Grade') #------------------------------------------------------------------------------ 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.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.axis([0, 100, 0.0, 1.0]) 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') #------------------------------------------------------------------------------ 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') #------------------------------------------------------------------------------ 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') (As an aside, if there are alternate algorithms for the Gaussian, S-, and Z-Curves, I'm open to those. The Gaussian doesn't reach y=0 at the ends.) Here's an example how I'm calling these: 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)] for row in varData: ... if row[4] == 'Decay S-Curve': functions.zCurve(row[10],row[9]) elif row[4] == 'Bell Curve': functions.gaussCurve(row[13],row[14]) elif row[4] == 'Growth S-Curve': functions.sCurve(row[8],row[11]) Two problems with mpl are: the inability to produce only the left and bottom axes (it insists on drawing a box with four axes) and the inability to allow me to define the lengths of the x- and y-axes (it insists that all plots must be square). I need rectangular plots (height half the width, for example) with only the left and bottom axes. If you PyX gurus point me in the proper direction I'll be very happy to translate my code from mpl and get on to labeling and the rest of the applicaiton. Thank you, Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation ; Voice: 503-667-4517 Fax: 503-667-8863 ```