コード例 #1
0
ファイル: log.py プロジェクト: 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()
コード例 #2
0
def main():
    from sfepy.base.conf import ProblemConf, get_standard_keywords
    from sfepy.fem import ProblemDefinition
    from sfepy.base.plotutils import pylab

    required, other = get_standard_keywords()
    # Use this file as the input file.
    conf = ProblemConf.from_file( __file__, required, other )

    # Create problem instance, but do not set equations.
    problem = ProblemDefinition.from_conf( conf,
                                           init_equations = False )

    options = Struct( output_filename_trunk = None )
    
    # Solve the problem. Output is ignored, results stored by using the
    # step_hook.
    u_t = solve_branch( problem, options, linear_tension )
    u_c = solve_branch( problem, options, linear_compression )

    # Get pressure load by calling linear_*() for each time step.
    ts = problem.get_timestepper()
    load_t = nm.array( [linear_tension( ts, nm.array( [[0.0]] ) )['val']
                        for aux in ts.iter_from( 0 )],
                       dtype = nm.float64 ).squeeze()
    load_c = nm.array( [linear_compression( ts, nm.array( [[0.0]] ) )['val']
                        for aux in ts.iter_from( 0 )],
                       dtype = nm.float64 ).squeeze()

    # Join the branches.
    displacements = {}
    for key in u_t.keys():
        displacements[key] = nm.r_[u_c[key][::-1], u_t[key]]
    load = nm.r_[load_c[::-1], load_t]

    if pylab is None:
        print 'pylab cannot be imported, printing raw data!'
        print displacements
        print load
    else:
        legend = []
        for key, val in displacements.iteritems():
            pylab.plot( load, val )
            legend.append( key )

        pylab.legend( legend, loc = 2 )
        pylab.xlabel( 'tension [kPa]' )
        pylab.ylabel( 'displacement [mm]' )
        pylab.grid( True )

        pylab.gcf().savefig( 'pressure_displacement.png' )
        pylab.show()
コード例 #3
0
ファイル: phono.py プロジェクト: certik/sfepy
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
コード例 #4
0
ファイル: phono.py プロジェクト: certik/sfepy
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 
コード例 #5
0
ファイル: phono.py プロジェクト: certik/sfepy
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