Example #1
0
 def plot(self, *args, **kwds):
     axis = kwds.pop('axis', None)
     if axis is None:
         axis = plt.gca()
     tmp = None
     default_plotflag = self.plot_kwds.get('plotflag')
     plotflag = kwds.get('plotflag', default_plotflag)
     if not plotflag and self.children is not None:
         axis.hold('on')
         tmp = []
         child_args = kwds.pop('plot_args_children',
                               tuple(self.plot_args_children))
         child_kwds = dict(self.plot_kwds_children).copy()
         child_kwds.update(kwds.pop('plot_kwds_children', {}))
         child_kwds['axis'] = axis
         for child in self.children:
             tmp1 = child.plot(*child_args, **child_kwds)
             if tmp1 is not None:
                 tmp.append(tmp1)
         if len(tmp) == 0:
             tmp = None
     main_args = args if len(args) else tuple(self.plot_args)
     main_kwds = dict(self.plot_kwds).copy()
     main_kwds.update(kwds)
     main_kwds['axis'] = axis
     tmp2 = self.plotter.plot(self, *main_args, **main_kwds)
     return tmp2, tmp
Example #2
0
def tallibing(x, y, n, **kwds):
    '''
    TALLIBING  Display numbers on field-plot
    
    CALL h=tallibing(x,y,n,size,color)
    
    x,y    = position matrices
    n      = the corresponding matrix of the values to be written
             (non-integers are rounded)
    size   = font size (optional) (default=8)
    color  = color of text (optional) (default='white')
    h      = column-vector of handles to TEXT objects
    
    TALLIBING writes the numbers in a 2D array as text at the positions 
    given by the x and y coordinate matrices.
    When plotting binned results, the number of datapoints in each
    bin can be written on the bins in the plot.
    
    Example
    ------- 
    >>> import wafo.graphutil as wg
    >>> import wafo.demos as wd
    >>> [x,y,z] = wd.peaks(n=20) 
    >>> h0 = wg.epcolor(x,y,z)
    >>> h1 = wg.tallibing(x,y,z)
      
    pcolor(x,y,z); shading interp; 
    
    See also
    --------
    text
    '''
    
    axis = kwds.pop('axis',None)
    if axis is None:
        axis = plotbackend.gca()
    
    x, y, n = np.atleast_1d(x, y, n)
    if mlab.isvector(x) or mlab.isvector(y): 
        x, y = np.meshgrid(x,y)
    
    x = x.ravel()
    y = y.ravel()
    n = n.ravel()
    n = np.round(n)
    
    # delete tallibing object if it exists 
    delete_text_object(_TALLIBING_GID, axis=axis)
     
    txtProp = dict(gid=_TALLIBING_GID, size=8, color='w', horizontalalignment='center',
                     verticalalignment='center', fontweight='demi', axes=axis)
     
    txtProp.update(**kwds)
    h = []
    for xi,yi, ni in zip(x,y,n):
        if ni:
            h.append(axis.text(xi, yi, str(ni), **txtProp))
    plotbackend.draw_if_interactive()
    return h
Example #3
0
    def labelfig(self, axis=None):
        if axis is None:
            axis = plt.gca()

        try:
            return self._labelfig(axis)
        except Exception as err:
            warnings.warn(str(err))
Example #4
0
def epcolor(*args, **kwds):    
    '''
    Pseudocolor (checkerboard) plot with mid-bin positioning.
    
     h = epcolor(x,y,data)
     
     
     [x,y]= the axes corresponding to the data-positions. Vectors or
            matrices. If omitted, giving only data-matrix as inargument, the
            matrix-indices are used as axes.
     data = data-matrix
    
     EPCOLOR make a checkerboard plot where the data-point-positions are in
     the middle of the bins instead of in the corners, and the last column
     and row of data are used.
    
  
     Example:      
     >>> import wafo.demos as wd
     >>> import wafo.graphutil as wg
     >>> x, y, z = wd.peaks(n=20)
     >>> h = wg.epcolor(x,y,z)
    
     See also 
     --------
     pylab.pcolor
    '''
    axis = kwds.pop('axis',None)
    if axis is None:
        axis = plotbackend.gca()
    midbin = kwds.pop('midbin', True)
    if not midbin:
        ret =  axis.pcolor(*args,**kwds)
        plotbackend.draw_if_interactive()
        return ret

    nargin = len(args)
    data = np.atleast_2d(args[-1]).copy()
    M, N = data.shape
    if nargin==1:
        x = np.arange(N)
        y = np.arange(M)
    elif nargin==3:
        x, y = np.atleast_1d(*args[:-1])
        if min(x.shape)!=1: 
            x = x[0]
        if min(y.shape)!=1:
            y = y[:,0]
    else:
        raise ValueError('pcolor takes 3 or 1 inarguments! (x,y,data) or (data)')

    xx = _findbins(x)
    yy = _findbins(y)
    ret =  axis.pcolor(xx, yy, data, **kwds)
    plotbackend.draw_if_interactive()
    return ret
Example #5
0
 def plot(self, *args, **kwargs):
     kwds = kwargs.copy()
     axis = kwds.pop('axis', None)
     if axis is None:
         axis = plt.gca()
     default_plotflag = self.plot_kwds.get('plotflag')
     plotflag = kwds.get('plotflag', default_plotflag)
     tmp = None
     if not plotflag and self.children is not None:
         tmp = self._plot_children(axis, plotflag, kwds)
     main_args = args if len(args) else tuple(self.plot_args)
     main_kwds = dict(self.plot_kwds).copy()
     main_kwds.update(kwds)
     main_kwds['axis'] = axis
     tmp2 = self.plotter.plot(self, *main_args, **main_kwds)
     return tmp2, tmp
Example #6
0
 def labelfig(self, axis=None):
     if axis is None:
         axis = plt.gca()
     try:
         h = []
         for fun, txt in zip(
                 ('set_title', 'set_xlabel', 'set_ylabel', 'set_ylabel'),
                 (self.title, self.xlab, self.ylab, self.zlab)):
             if txt:
                 if fun.startswith('set_title'):
                     title0 = axis.get_title()
                     if title0.lower().strip() != txt.lower().strip():
                         txt = title0 + '\n' + txt
                 h.append(getattr(axis, fun)(txt))
         return h
     except:
         pass
Example #7
0
    def plot(self, axis=None):
        ''' Plot profile function with 100(1-alpha)% CI
        '''
        if axis is None:
            axis = plotbackend.gca()

        p_ci = self.get_bounds(self.alpha)
        axis.plot(
            self.args, self.data,
            self.args[[0, -1]], [self.Lmax, ] * 2, 'r--',
            self.args[[0, -1]], [self.alpha_cross_level, ] * 2, 'r--')
        axis.vlines(p_ci, ymin=axis.get_ylim()[0],
                    ymax=self.Lmax,  # self.alpha_cross_level,
                    color='r', linestyles='--')
        axis.set_title(self.title)
        axis.set_ylabel(self.ylabel)
        axis.set_xlabel(self.xlabel)
Example #8
0
 def plot(self, wdata, *args, **kwds):
     axis = kwds.pop('axis', None)
     if axis is None:
         axis = plt.gca()
     plotflag = kwds.pop('plotflag', False)
     if plotflag:
         h1 = self._plot(axis, plotflag, wdata, *args, **kwds)
     else:
         if isinstance(wdata.data, (list, tuple)):
             vals = tuple(wdata.data)
         else:
             vals = (wdata.data,)
         if isinstance(wdata.args, (list, tuple)):
             args1 = tuple((wdata.args)) + vals + args
         else:
             args1 = tuple((wdata.args,)) + vals + args
         plotfun = getattr(axis, self.plotmethod)
         h1 = plotfun(*args1, **kwds)
     h2 = wdata.labels.labelfig(axis)
     return h1, h2
Example #9
0
    def plot(self, axis=None):
        """ Plot profile function with 100(1-alpha)% CI
        """
        if axis is None:
            axis = plotbackend.gca()

        p_ci = self.get_bounds(self.alpha)
        axis.plot(
            self.args,
            self.data,
            self.args[[0, -1]],
            [self.Lmax] * 2,
            "r--",
            self.args[[0, -1]],
            [self.alpha_cross_level] * 2,
            "r--",
        )
        axis.vlines(
            p_ci, ymin=axis.get_ylim()[0], ymax=self.Lmax, color="r", linestyles="--"  # self.alpha_cross_level,
        )
        axis.set_title(self.title)
        axis.set_ylabel(self.ylabel)
        axis.set_xlabel(self.xlabel)
Example #10
0
mM.plot()
plt.title('min-max cycle pairs')
plt.subplot(121),
mM_rfc.plot()
plt.title('Rainflow filtered cycles')
plt.show()

#! Min-max and rainflow cycle distributions
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import wafo.misc as wm
ampmM_sea = mM.amplitudes()
ampRFC_sea = mM_rfc.amplitudes()
plt.clf()
plt.subplot(121)
wm.plot_histgrm(ampmM_sea, 25)
ylim = plt.gca().get_ylim()
plt.title('min-max amplitude distribution')
plt.subplot(122)
wm.plot_histgrm(ampRFC_sea, 25)
plt.gca().set_ylim(ylim)
plt.title('Rainflow amplitude distribution')
plt.show()

#!#! Section 4.3.3 Simulation of rainflow cycles
#!#! Simulation of cycles in a Markov model
# n = 41
# param_m = [-1, 1, n]
# param_D = [1, n, n]
# u_markov=levels(param_m);
# G_markov=mktestmat(param_m,[-0.2, 0.2],0.15,1);
# T_markov=5000;
Example #11
0
mM.plot()
plt.title('min-max cycle pairs')
plt.subplot(121),
mM_rfc.plot()
plt.title('Rainflow filtered cycles')
plt.show()

#! Min-max and rainflow cycle distributions
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import wafo.misc as wm
ampmM_sea = mM.amplitudes()
ampRFC_sea = mM_rfc.amplitudes()
plt.clf()
plt.subplot(121)
wm.plot_histgrm(ampmM_sea,25)
ylim = plt.gca().get_ylim()
plt.title('min-max amplitude distribution')
plt.subplot(122)
wm.plot_histgrm(ampRFC_sea,25)
plt.gca().set_ylim(ylim)
plt.title('Rainflow amplitude distribution')
plt.show()

#!#! Section 4.3.3 Simulation of rainflow cycles
#!#! Simulation of cycles in a Markov model
# n = 41
# param_m = [-1, 1, n]
# param_D = [1, n, n]
# u_markov=levels(param_m);
# G_markov=mktestmat(param_m,[-0.2, 0.2],0.15,1);
# T_markov=5000;
Example #12
0
def tallibing(*args, **kwds):
    '''
    TALLIBING  Display numbers on field-plot

    CALL h=tallibing(x,y,n,size,color)

    Parameters
    ----------
    x, y : array
        position matrices
    n : array
        corresponding matrix of the values to be written
             (non-integers are rounded)
    mid_points : bool (default True)
        data-point-positions are in the middle of bins instead of the corners
    size : int, (default=8)
        font size (optional)
    color : str, (default='white')
        color of text (optional)

    Returns
    -------
    h : list
        handles to TEXT objects

    TALLIBING writes the numbers in a 2D array as text at the positions
    given by the x and y coordinate matrices.
    When plotting binned results, the number of datapoints in each
    bin can be written on the bins in the plot.

    Example
    -------
    >>> import wafo.graphutil as wg
    >>> import wafo.demos as wd
    >>> [x,y,z] = wd.peaks(n=20)
    >>> h0 = wg.pcolor(x,y,z)
    >>> h1 = wg.tallibing(x,y,z)

    See also
    --------
    text
    '''

    axis = kwds.pop('axis', None)
    if axis is None:
        axis = plotbackend.gca()

    x, y, n = _parse_data(*args, **kwds)
    if mlab.isvector(x) or mlab.isvector(y):
        x, y = np.meshgrid(x, y)

    n = np.round(n)

    # delete tallibing object if it exists
    delete_text_object(_TALLIBING_GID, axis=axis)

    txtProp = dict(gid=_TALLIBING_GID,
                   size=8,
                   color='w',
                   horizontalalignment='center',
                   verticalalignment='center',
                   fontweight='demi',
                   axes=axis)

    txtProp.update(**kwds)
    h = []
    for xi, yi, ni in zip(x.ravel(), y.ravel(), n.ravel()):
        if ni:
            h.append(axis.text(xi, yi, str(ni), **txtProp))
    plotbackend.draw_if_interactive()
    return h
Example #13
0
def tallibing(*args, **kwds):
    '''
    TALLIBING  Display numbers on field-plot

    CALL h=tallibing(x,y,n,size,color)

    Parameters
    ----------
    x, y : array
        position matrices
    n : array
        corresponding matrix of the values to be written
             (non-integers are rounded)
    mid_points : bool (default True)
        data-point-positions are in the middle of bins instead of the corners
    size : int, (default=8)
        font size (optional)
    color : str, (default='white')
        color of text (optional)

    Returns
    -------
    h : list
        handles to TEXT objects

    TALLIBING writes the numbers in a 2D array as text at the positions
    given by the x and y coordinate matrices.
    When plotting binned results, the number of datapoints in each
    bin can be written on the bins in the plot.

    Example
    -------
    >>> import wafo.graphutil as wg
    >>> import wafo.demos as wd
    >>> [x,y,z] = wd.peaks(n=20)
    >>> h0 = wg.pcolor(x,y,z)
    >>> h1 = wg.tallibing(x,y,z)

    See also
    --------
    text
    '''

    axis = kwds.pop('axis', None)
    if axis is None:
        axis = plotbackend.gca()

    x, y, n = _parse_data(*args, **kwds)
    if mlab.isvector(x) or mlab.isvector(y):
        x, y = np.meshgrid(x, y)

    n = np.round(n)

    # delete tallibing object if it exists
    delete_text_object(_TALLIBING_GID, axis=axis)

    txtProp = dict(gid=_TALLIBING_GID, size=8, color='w',
                   horizontalalignment='center',
                   verticalalignment='center', fontweight='demi', axes=axis)

    txtProp.update(**kwds)
    h = []
    for xi, yi, ni in zip(x.ravel(), y.ravel(), n.ravel()):
        if ni:
            h.append(axis.text(xi, yi, str(ni), **txtProp))
    plotbackend.draw_if_interactive()
    return h