Exemplo n.º 1
0
def display1D(t, slot=0, gridPos=(0,0), gridSize=(-1,-1),
              bgBlend=1., var1='', var2='',
              r1=None, r2=None):
    """Display 1D plots.
    Usage: display1D(t, slot, ....)"""
    import Converter
    if len(t) > 0 and isinstance(t[0], numpy.ndarray): # as numpys
        if len(t) < 2:
            raise ValueError('display1D: requires at least two numpys [x,y]')
        x = t[0]; y = t[1]
        n = x.size
        array = Converter.array(var1+','+var2,n,1,1)
        array[1][0,:] = x[:]
        array[1][1,:] = y[:]
        arrays = [array]
    else:
        arrays = C.getAllFields(t, 'nodes') # as pyZone
    CPlot.display1D(arrays, slot, gridPos, gridSize, bgBlend, 
                    var1, var2, r1, r2)
# - display1D (array) -
import Generator as G
import CPlot
import Transform as T
import Converter as C
import numpy

# 1D data defined in arrays
b = G.cart((0, 0, 0), (0.1, 1, 1), (50, 1, 1))
c = G.cart((5, 0, 0), (0.1, 1, 1), (50, 1, 1))
B = [b, c]
CPlot.setState(gridSize=(1, 2))
for i in xrange(100):
    B = C.initVars(B, 'f=sin({x}+0.02*%d)' % i)
    B = C.initVars(B, 'g={x}')
    CPlot.display1D(B, slot=0, bgBlend=1., gridPos=(0, 0), var1='x', var2='f')

# 1D data defined in numpys
x = numpy.linspace(0, 2 * numpy.pi)
y = numpy.sin(x)
CPlot.display1D([x, y], slot=1, var1='x', var2='y', gridPos=(0, 1), bgBlend=0.)