#!/usr/bin/env python # (C) 2000 Huaiyu Zhu <hzhu@users.sourceforge.net>. Licence: GPL # $Id: test_gplot.py,v 1.6 2000/10/05 01:28:27 hzhu Exp $ """ Test gplot module """ from MatPy.Matrix import r_range, rand, cumsum from MatPy.efuncs import sin, cos, exp, sqrt from MatPy.gplot import Gplot if __name__ == "__main__": waittime = None else: waittime = 3 g = Gplot() #from MatPy import nothing #g = nothing #------------------------------------------------------------------ title = "Gplot.plot : Plot four curves" print title x1 = r_range(100)/4.0 y1 = sin(x1)/2 - 1 x = r_range(300)/5.0 y2 = cos(sqrt(x)*10)/3 y3 = x.__tpow__(4); y3 = 2*y3/max(y3) y4 = 1-exp(-x/3); print y1.shape, y2.shape, y3.shape, y4.shape g.title(title) g.xlabel('x') g.ylabel('y') g.text((31,-0.8), "first label") g.text((21,1.2), "second label") g.plot((y1, y2, y3, y4), names=("sin x - 1", "cos sqrt x", "x^4", "1-e^-x"), xs=[x1] + [x]*3) g.hardcopy("plot.ps") g.wait(waittime) g = Gplot() # There seems no way to remove texts #g = nothing #------------------------------------------------------------------ title = """Gplot.mesh : mesh z against x and y """ print title g.title(title) g.xlabel('x') g.ylabel('y') x = r_range(40)/2.0 y = r_range(30)/10.0 - 1.5 for i in range(10): a = (sin(x+i) + 0.1*x).T b = y.__tpow__(2) m = a.__tsub__(b) #print m.shape, a.shape, b.shape g.mesh(m, x, y).wait(0.4) # On my linux box this is necessary for disk sync? g.hardcopy("mesh.ps") g.wait(waittime) #------------------------------------------------------------------ title = "Gplot.plot : Using matrix columns as y" print title ys = rand((30,4)) g.title(title) g.plot(ys).wait(waittime) #------------------------------------------------------------------ title = "Gplot.plot : Using matrix as part of x, the rest default to index" print title xs = rand((30,2)) ys = cumsum(ys) xs = cumsum(xs) g.title(title) g.plot(ys, xs).wait(waittime) #------------------------------------------------------------------ title = "Gplot.holdon Gplot.holdoff : Plotting 10 lines in sequence" print title from MatPy.Matrix import cumsum, Matrix_c, zeros from MatPy.Stats.distribs import randn g.title(title) g.holdon for i in range(5): ys = Matrix_c([zeros((1,2)), randn((30,2))]) g.plot(cumsum(ys)).wait(0.2) g.wait(waittime) g.holdoff #------------------------------------------------------------------ title = "Gplot.plotlines : Plot 8 lines, each composed 2d points" print title from MatPy.Matrix import max, max2 from MatPy.efuncs import abs g.title(title) lines = [] M = 0 for i in range(8): line = cumsum(randn((90,2))) lines.append(line) g.text(line[-1]*1.3, '%s'%i) M = max(max2(abs(line)), M) M = M*1.3 g.axis((-M,M), (0,0), equal=1) g.plotlines(lines).wait(waittime)
Result obtained with
>>> from MatPy.tests import test_gplot
Gplot.plot : Plot four curves (1, 100) (1, 300) (1, 300) (1, 300) Gplot.mesh : mesh z against x and y Gplot.plot : Using matrix columns as y Gplot.plot : Using matrix as part of x, the rest default to index Gplot.holdon Gplot.holdoff : Plotting 10 lines in sequence Gplot.plotlines : Plot 8 lines, each composed 2d points