Exemplo n.º 1
0
Arquivo: log.py Projeto: certik/sfepy
    def __call__(self, queue, data_names, igs, seq_data_names, yscales, xaxes, yaxes):
        """Sets-up the plotting window, sets GTK event loop timer callback to
        callback() returned by self.poll_draw(). The callback does the actual
        plotting, taking commands out of `queue`, and is called every second."""
        self.output("starting plotter...")
        #        atexit.register( self.terminate )

        self.queue = queue
        self.data_names = data_names
        self.igs = igs
        self.seq_data_names = seq_data_names
        self.yscales = yscales
        self.xaxes = xaxes
        self.yaxes = yaxes
        self.n_gr = len(data_names)

        self.fig = pylab.figure()

        self.ax = []
        for ig in range(self.n_gr):
            isub = 100 * self.n_gr + 11 + ig
            self.ax.append(self.fig.add_subplot(isub))

        self.gid = gobject.timeout_add(1000, self.poll_draw())

        self.output("...done")

        pylab.show()
Exemplo n.º 2
0
def plot_logs( fig_num, plot_rsc, plot_labels,
               freqs, logs, valid, freq_range, plot_range, squared,
               draw_eigs = True, show_legend = True, show = False,
               clear = False, new_axes = False ):
    """
    Plot logs of min/max eigs of M.
    """
    if pylab is None: return

    fig = pylab.figure( fig_num )
    if clear:
        fig.clf()
    if new_axes:
        ax = fig.add_subplot( 111 )
    else:
        ax = fig.gca()

    if draw_eigs:
        aux = plot_eigs( fig_num, plot_rsc, plot_labels, valid, freq_range,
                         plot_range )

    for ii, log in enumerate( logs ):
        l1 = ax.plot( freqs[ii], log[:,0], **plot_rsc['eig_min'] )
        l2 = ax.plot( freqs[ii], log[:,-1], **plot_rsc['eig_max'] )
    l1[0].set_label( plot_labels['eig_min'] )
    l2[0].set_label( plot_labels['eig_max'] )

    fmin, fmax = freqs[0][0], freqs[-1][-1]
    ax.plot( [fmin, fmax], [0, 0], **plot_rsc['x_axis'] )

    if squared:
        ax.set_xlabel( r'$\lambda$, $\omega^2$' )
    else:
        ax.set_xlabel( r'$\sqrt{\lambda}$, $\omega$' )

    ax.set_ylabel( plot_labels['y_axis'] )

    if new_axes:
        ax.set_xlim( [fmin, fmax] )
        ax.set_ylim( plot_range )

    if show_legend:
        ax.legend()

    if show:
        pylab.show()
    return fig
Exemplo n.º 3
0
def plot_eigs( fig_num, plot_rsc, plot_labels, valid, freq_range, plot_range,
               show = False, clear = False, new_axes = False ):
    """
    Plot resonance/eigen-frequencies.

    `valid` must correspond to `freq_range`

    resonances : red
    masked resonances: dotted red
    """
    if pylab is None: return
    assert_( len( valid ) == len( freq_range ) )

    fig = pylab.figure( fig_num )
    if clear:
        fig.clf()
    if new_axes:
        ax = fig.add_subplot( 111 )
    else:
        ax = fig.gca()

    l0 = l1 = None
    for ii, f in enumerate( freq_range ):
        if valid[ii]:
            l0 = ax.plot( [f, f], plot_range, **plot_rsc['resonance'] )[0]
        else:
            l1 = ax.plot( [f, f], plot_range, **plot_rsc['masked'] )[0]
 
    if l0:
        l0.set_label( plot_labels['resonance'] )
    if l1:
        l1.set_label( plot_labels['masked'] )

    if new_axes:
        ax.set_xlim( [freq_range[0], freq_range[-1]] )
        ax.set_ylim( plot_range )

    if show:
        pylab.show()
    return fig 
Exemplo n.º 4
0
def plot_gaps( fig_num, plot_rsc, gaps, kinds, freq_range,
               plot_range, show = False, clear = False, new_axes = False ):
    """ """
    if pylab is None: return

    def draw_rect( ax, x, y, rsc ):
        ax.fill( nm.asarray( x )[[0,1,1,0]],
                 nm.asarray( y )[[0,0,1,1]],
                 **rsc )

    fig = pylab.figure( fig_num )
    if clear:
        fig.clf()
    if new_axes:
        ax = fig.add_subplot( 111 )
    else:
        ax = fig.gca()

    # Colors.
    strong = plot_rsc['strong_gap']
    weak = plot_rsc['weak_gap']
    propagation = plot_rsc['propagation']

    for ii in xrange( len( freq_range ) - 1 ):
        f0, f1 = freq_range[[ii, ii+1]]
        gmin, gmax = gaps[ii]
        kind, kind_desc = kinds[ii]

        if kind == 'p':
            draw_rect( ax, (f0, f1), plot_range, propagation )
            info = [(f0, f1)]
        elif kind == 'w':
            draw_rect( ax, (f0, f1), plot_range, weak )
            info = [(f0, f1)]
        elif kind == 'wp':
            draw_rect( ax, (f0, gmin[1]), plot_range, weak )
            draw_rect( ax, (gmin[1], f1), plot_range, propagation )
            info = [(f0, gmin[1]), (gmin[1], f1)]
        elif kind == 's':
            draw_rect( ax, (f0, f1), plot_range, strong )
            info = [(f0, f1)]
        elif kind == 'sw':
            draw_rect( ax, (f0, gmax[1]), plot_range, strong )
            draw_rect( ax, (gmax[1], f1), plot_range, weak )
            info = [(f0, gmax[1]), (gmax[1], f1)]
        elif kind == 'swp':
            draw_rect( ax, (f0, gmax[1]), plot_range, strong )
            draw_rect( ax, (gmax[1], gmin[1]), plot_range, weak )
            draw_rect( ax, (gmin[1], f1), plot_range, propagation )
            info = [(f0, gmax[1]), (gmax[1], gmin[1]), (gmin[1], f1)]
        else:
            output( 'impossible band gap combination:' )
            output( gmin, gmax )
            raise ValueError

        output( ii, gmin[0], gmax[0], '%.8f' % f0, '%.8f' % f1 )
        output( ' -> %s\n    %s' %(kind_desc, info) )

    if new_axes:
        ax.set_xlim( [freq_range[0], freq_range[-1]] )
        ax.set_ylim( plot_range )

    if show:
        pylab.show()
    return fig