コード例 #1
0
    def build_layer(self, layer, group_info):
        """
        Returns a list of gnuplot commands that need to be executed
        to draw this layer.
        group_info is a dictionary containing information for grouped lines.        
        """

        rv = []

        # visible
        if uwrap.get(layer, 'visible') is False:
            return rv
        
        # title
        title = uwrap.get(layer, 'title')
        if title is not None: rv.append('set title "%s"' % title)
        else: rv.append("unset title")

        # grid
        grid = uwrap.get(layer, 'grid')
        if grid is True: rv.append('set grid')
        else: rv.append('unset grid')
        
        rv.extend(self.update_legend(layer))
        rv.extend(self.update_axes(layer))
        rv.extend(self.update_labels(layer))
        rv.extend(self.update_lines(layer))

        return rv
コード例 #2
0
    def update_axes(self, layer, updateinfo={}):
        # updateinfo is ignored
        cl = []
        # axes
        for key, axis in layer.axes.iteritems():            
            # axis format
            format = uwrap.get(axis, 'format')
            if format is not None: cl.append('set format %s "%s"' % (key, format))
            else: cl.append('set format %s' % key)

            # axis label
            label = uwrap.get(axis, 'label')
            if label is not None: cl.append('set %slabel "%s"' % (key, label))
            else: cl.append('unset %slabel' % key)

            # axis range
            start = uwrap.get(axis, 'start','*')
            end = uwrap.get(axis, 'end','*')
            cl.append('set %srange [%s:%s]' % (key,start,end))

            # axis scale
            scale = uwrap.get(axis, 'scale')
            if scale == 'linear': cl.append('unset log %s' % key)
            elif scale == 'log': cl.append('set log %s' % key)
            else:
                logger.error("Axis scale '%s' not supported by this backend." % scale)

        self.cmd_dict['axes'] = cl                
        return cl
コード例 #3
0
 def get_line_label(self, line, table=None, cy=None):
     #:line.label:OK
     label = line.label
     if label is None:
         if table is not None and cy is not None:
             column = table.column(cy)
             label = column.label or column.key or uwrap.get(line, 'label')
         else:
             label = uwrap.get(line, 'label')
     return label
コード例 #4
0
    def redraw(self, rebuild_cache=True):

        # All commands for gnuplot are appended to the cmd_list,
        # so that they can be executed at the very end.
        cmd_list = []
        cmd_list.append('cd "%s"' % self.tmpdir)
	cmd_list.append( "set encoding %s" % self.encoding )

        cmd_list += self.terminal.build(self)     

        # multiplot ?
        if len(self.plot.layers) > 1:
            cmd_list.append( "set multiplot" )
            for layer in self.plot.layers:
                group_info = {}
                x, y = uwrap.get(layer, 'x'), uwrap.get(layer, 'y')
                width, height = uwrap.get(layer, 'width'), uwrap.get(layer, 'height')
                cmd_list.append("set origin %.2f,%.2f" % (x,y))
                cmd_list.append("set size %.2f,%.2f" % (width, height))
                cmd_list += self.build_layer(layer, group_info)
            cmd_list.append( "unset multiplot" )
        else:
            # Single plot!
            # create plotting commands from the Layer information
            group_info = {}
            cmd_list += self.build_layer(self.plot.layers[0], group_info)

        self.export_datasets()
       
        # Now execute all collected commands.
        print "cmd list is: "
        for cmd in cmd_list:
            print "   ", cmd
        print
        
        Signals.emit(self, 'gnuplot-start-plotting')
        logger.info("Gnuplot command list:\n\n%s" % "\n".join(cmd_list))
        for cmd in cmd_list:
            self(cmd)

        Signals.emit(self,'gnuplot-after-plot', window_title=self.window_title)
コード例 #5
0
    def legend_kwargs(self, legend, layer):
        """
        'border' must be popped and set via legend.draw_frame
        'visible' must be popped and set via set_visible
        """

        visible = uwrap.get(legend, 'visible')
                    
        #:legend.label:TODO
        label = uwrap.get(legend, 'visible')
        if label is not None:
            pass

        #:legend.border:OK
        # (see below but keep it here!)
        border = uwrap.get(legend, 'border')

        #:legend.position TODO
        position = uwrap.get(legend, 'position', 'best')
        if position == 'at position':
            position = (uwrap.get(legend, 'x'), uwrap.get(legend, 'y'))

        # create legend entries from line labels
        line_cache = self.line_caches[layer]
        labels = [l.get_label() for l in line_cache]

        return {'handles' : line_cache,
                'labels' : labels,
                'loc' : position,
                'border' : border,
                'visible' : visible}
コード例 #6
0
    def update_lines(self, layer, updateinfo={}):
        # updateinfo is ignored

        cl = []
        # lines
        line_cache = []
        for line in layer.lines:
            try:
                if uwrap.get(line, 'visible') is False: continue

                ds = self.get_line_source(line)
                table = self.get_table(ds)
                cx, cy = self.get_column_indices(line)
                
                # mark source for export            
                filename = self.mark_for_export(ds)
                if filename is None:
                    continue
                source = '"%s"' % filename

                label = self.get_line_label(line, table=table, cy=cy)
                if label is not None: title = 'title "%s"' % label
                else: title = 'notitle'

                using = 'using %s:%s' % (cx+1,cy+1)

                # TODO: support 'style' and 'marker'
                # with-clause
                type = uwrap.get(line, 'style')
                type_mappings = {'solid': 'w l'}
                try:
                    with = type_mappings[type]
                except KeyError:
                    with = ''
                    logger.error('line type "%s" not supported by this backend.' % type )

                # line width
                width = uwrap.get(line, 'width')
                width = 'lw %s' % str(width)
コード例 #7
0
    def update_legend(self, layer, updateinfo={}):
        # updateinfo is ignored

        cl = []
        #:legend
        # (aka key in gnuplot)
        legend = uwrap.get(layer, 'legend')
        if legend is not None:
            #:legend.visible
            visible = uwrap.get(legend, 'visible')
            if visible is True:
                #:legend.label
                label = uwrap.get(legend, 'label')                
                if label is not None: key_title = 'title "%s"' % label
                else: key_title = ""

                #:legend.border:OK
                border = uwrap.get(legend, 'border')
                if border is True: key_border = "box"
                else: key_border = "nobox"

                # legend positioning
                position_mapping = {
                    'center' : 'graph 0.5, graph 0.5',
                    'lower left' : 'graph 0.0, graph 0.0',
                    'center right' : 'graph 1.0, graph 0.5',
                    'upper left' : 'graph 0.0, graph 1.0',
                    'center left' : 'graph 0.0, graph 0.5',
                    'upper right' : 'graph 1.0, graph 1.0',
                    'lower right' : 'graph 1.0, graph 0.0',
                    'upper center' : 'graph 0.5, graph 1.0',
                    'lower center' : 'graph 0.5, graph 0.0',
                    'outside' : 'outside'
                    }
                pos = uwrap.get(legend, 'position')
                if pos == 'best':
                    key_pos = ''
                elif pos == 'at position':
                    if legend.x is None and legend.y is None:
                        key_pos = ''
                    else:
                        x = uwrap.get(legend, 'x')
                        y = uwrap.get(legend, 'y')
                        key_pos = 'graph %.2f, graph %.2f' % (x, y)
                else:
                    key_pos = position_mapping[pos]

                cl.append("set key %(key_pos)s %(key_title)s %(key_border)s" % locals())
            else:
                cl.append("unset key")                

        self.cmd_dict['legend'] = cl
        return cl
コード例 #8
0
 def model_row_from_line(self, line):
     source = uwrap.get(line, 'source')
     if source is not None: source_key = source.key
     else: source_key = ""
     return [line,
             uwrap.get(line, 'visible'),
             line.label or "",
             line.style or "",
             line.marker or "",
             line.width or "",
             source_key,
             str(uwrap.get(line, 'cx',"")),
             str(uwrap.get(line, 'cy',"")),
             str(uwrap.get(line, 'row_first',"")),
             str(uwrap.get(line, 'row_last',"")),                
             str(uwrap.get(line, 'cxerr',"")),
             str(uwrap.get(line, 'cyerr',""))]
コード例 #9
0
    def toggle_logscale_y(self, plot, layer, undolist=None):
        project = self.app.project
        if undolist is None:
            undolist = project.journal
            
        ul = UndoList().describe("Toggle logarithmic scale")

        axis = layer.request_axis("y", undolist=ul)
        if axis.scale != 'log':
            uwrap.set(axis, scale='log', undolist=ul)
            start = uwrap.get(axis, 'start')
            if start is not None and start < 0:
                uwrap.set(axis, start=None, undolist=ul)
        else:
            uwrap.set(axis, scale='linear', undolist=ul)

        uwrap.emit_last( plot, "plot-changed", undolist=ul )
        undolist.append(ul)
コード例 #10
0
    def toggle_logscale_y(self, plot, layer, undolist=None):
        project = self.app.project
        if undolist is None:
            undolist = project.journal
            
        ul = UndoList().describe("Toggle logarithmic scale")

        axis = layer.yaxis
        if axis.scale != 'log':
            uwrap.set(axis, scale='log', undolist=ul)
            updateinfo.update['scale'] = 'log'
            
            start = uwrap.get(axis, 'start')
            if start is not None and start < 0:
                uwrap.set(axis, start=None, undolist=ul)
                updateinfo.update['start'] = None
        else:
            uwrap.set(axis, scale='linear', undolist=ul)

        # TODO: replace by something like
        #uwrap.emit_last(layer, "notify::axes", updateinfo=updateinfo, undolist=ul)
        uwrap.emit_last( plot, "plot-changed", undolist=ul )
        undolist.append(ul)
コード例 #11
0
    def redraw(self, rebuild_cache=True):

        # All commands for gnuplot are appended to the cmd_list,
        # so that they can be executed at the very end.
        cmd_list = []
        cmd_list.append('cd "%s"' % self.tmpdir)
	cmd_list.append( "set encoding %s" % self.encoding )

        cmd_list += self.terminal.build(self)     

        # multiplot ?
        if len(self.plot.layers) > 1:
            cmd_list.append( "set multiplot" )
            for layer in self.plot.layers:
                group_info = {}
                x, y = uwrap.get(layer, 'x'), uwrap.get(layer, 'y')
                width, height = uwrap.get(layer, 'width'), uwrap.get(layer, 'height')
                cmd_list.append("set origin %.2f,%.2f" % (x,y))
                cmd_list.append("set size %.2f,%.2f" % (width, height))
                cmd_list += self.build_layer(layer, group_info)
            cmd_list.append( "unset multiplot" )
        else:
            # Single plot!
            # create plotting commands from the Layer information
            group_info = {}
            cmd_list += self.build_layer(self.plot.layers[0], group_info)


        # Export Datasets to temporary directory, so that
        # gnuplot can access them.
        exporter = ExporterRegistry.new_instance('ASCII')
        
        destdir = self.tmpdir
        for (source, value) in self.exports.iteritems():
            (filename, change_counter, ds) = value
            if ds is None:
                logger.warn("One of the Datasets to export is None.")
                continue
            if ds.is_empty():
                logger.warn("One of the Datasets to export is empty")
                continue
            logging.debug("Change counter %d, old %d" % (ds.change_counter, change_counter))
            if ds.has_changes(change_counter):                              
                filename = os.path.join(destdir, filename)
                logger.debug('exporting "%s" to dir "%s"' % (ds, destdir))            
                exporter.write_to_file(filename, ds.data)
                self.exports[source][1] = ds.change_counter
            else:
                logger.info("Dataset has not changed and is not exported!")
                
       
        # Now execute all collected commands.
        print "cmd list is: "
        for cmd in cmd_list:
            print "   ", cmd
        print
        
        Signals.emit(self, 'gnuplot-start-plotting')
        logger.info("Gnuplot command list:\n\n%s" % "\n".join(cmd_list))
        for cmd in cmd_list:
            self(cmd)

        Signals.emit(self,'gnuplot-after-plot', window_title=self.window_title)
コード例 #12
0
    def build_layer(self, layer, group_info):
        """
        Returns a list of gnuplot commands that need to be executed
        to draw this layer.
        group_info is a dictionary containing information for grouped lines.        
        """

        rv = []

        # visible
        if uwrap.get(layer, 'visible') is False:
            return rv
        
        # title
        title = uwrap.get(layer, 'title')
        if title is not None: rv.append('set title "%s"' % title)
        else: rv.append("unset title")

        # grid
        grid = uwrap.get(layer, 'grid')
        if grid is True: rv.append('set grid')
        else: rv.append('unset grid')

        #:legend
        # (aka key in gnuplot)
        legend = uwrap.get(layer, 'legend')
        if legend is not None:
            #:legend.visible
            visible = uwrap.get(legend, 'visible')
            if visible is True:
                #:legend.label
                label = uwrap.get(legend, 'label')
                if label is not None: key_title = 'title "%s"' % label
                else: key_title = ""

                #:legend.border
                border = uwrap.get(legend, 'border')
                if border is True: key_border = "box"
                else: key_border = "nobox"

                # legend positioning
                position_mapping = {
                    'center' : 'graph 0.5, graph 0.5',
                    'lower left' : 'graph 0.0, graph 0.0',
                    'center right' : 'graph 1.0, graph 0.5',
                    'upper left' : 'graph 0.0, graph 1.0',
                    'center left' : 'graph 0.0, graph 0.5',
                    'upper right' : 'graph 1.0, graph 1.0',
                    'lower right' : 'graph 1.0, graph 0.0',
                    'upper center' : 'graph 0.5, graph 1.0',
                    'lower center' : 'graph 0.5, graph 0.0',
                    'outside' : 'outside'
                    }
                pos = uwrap.get(legend, 'position')
                if pos == 'best':
                    key_pos = ''
                elif pos == 'at position':
                    if legend.x is None and legend.y is None:
                        key_pos = ''
                    else:
                        x = uwrap.get(legend, 'x')
                        y = uwrap.get(legend, 'y')
                        key_pos = 'graph %.2f, graph %.2f' % (x, y)
                else:
                    key_pos = position_mapping[pos]

                rv.append("set key %(key_pos)s %(key_title)s %(key_border)s" % locals())
            else:
                rv.append("unset key")                

        # axes
        for key, axis in layer.axes.iteritems():            
            # axis format
            format = uwrap.get(axis, 'format')
            if format is not None: rv.append('set format %s "%s"' % (key, format))
            else: rv.append('set format %s' % key)

            # axis label
            label = uwrap.get(axis, 'label')
            if label is not None: rv.append('set %slabel "%s"' % (key, label))
            else: rv.append('unset %slabel' % key)

            # axis range
            start = uwrap.get(axis, 'start','*')
            end = uwrap.get(axis, 'end','*')
            rv.append('set %srange [%s:%s]' % (key,start,end))

            # axis scale
            scale = uwrap.get(axis, 'scale')
            if scale == 'linear': rv.append('unset log %s' % key)
            elif scale == 'log': rv.append('set log %s' % key)
            else:
                logger.error("Axis scale '%s' not supported by this backend." % scale)

        # lines
        line_cache = []
        for line in layer.lines:
            if uwrap.get(line, 'visible') is False: continue

            # mark source for export 
            filename = self.mark_for_export(uwrap.get(line, 'source'))
            if filename is None:
                continue
            source = '"%s"' % filename
            
            # title-clause
            label = uwrap.get(line, 'label')
            if label is not None: title = 'title "%s"' % label
            else: title = 'notitle'

            # using-clause
            # TODO: only do this if we have a group
            # TODO: on the other hand, we should only advance
            # TODO: cx/cy if we are talking about the same source!
            if 1 == 0:
                cx = line.cx or group_info.get('cx', 1)
                group_info['cx'] = cx + 2
                cy = line.cy or group_info.get('cy', 2)
                group_info['cy'] = cy + 2
            else:
                (cx, cy) = (line.cx, line.cy)
                if cx is None or cy is None:
                    logger.error("No source cx or cy given. Line skipped.")
                    continue
            using = 'using %s:%s' % (cx+1,cy+1)

            # TODO: support 'style' and 'marker'
            # with-clause
            type = uwrap.get(line, 'style')
            type_mappings = {'solid': 'w l'}
            try:
                with = type_mappings[type]
            except KeyError:
                with = ''
                logger.error('line type "%s" not supported by this backend.' % type )
コード例 #13
0
    def update_line(self, line, layer, axes=None, updateinfo={}):
        # updateinfo is ignored
        
        axes = axes or self.layer_to_axes[layer]
        omap = self.omaps[layer]
        line_cache = self.line_caches[layer]

        data_to_plot = []

        #:line.visible
        if uwrap.get(line, 'visible') is False:
            if line in axes.lines:
                axes.lines.remove(line)
                line_cache.remove(line)
            omap[line] = None                    
            return

        ds = self.get_line_source(line)
        table = self.get_table(ds)
        cx, cy = self.get_column_indices(line)
        xdata, ydata = self.get_table_data(table, cx, cy)

        #:line.row_first
        #:line.row_last
        def limit_data(data, start, end):
            try:
                return data[start:end]
            except IndexError:
                backend.BackendError("Index range '%s'out of bounds!" % (start,end) )

        start, end = line.row_first, line.row_last
        xdata = limit_data(xdata, start, end)
        ydata = limit_data(ydata, start, end)


        #:line.style
        global linestyle_mappings
        style = uwrap.get(line, 'style', 'solid')
        style = linestyle_mappings[style]


        #:line.marker
        global linemarker_mappings
        marker = uwrap.get(line, 'marker', 'None')
        marker = linemarker_mappings[marker]

        #:line.width:OK

        #:line.color
        N = len(layer.group_colors)
        index = layer.lines.index(line)
        color = uwrap.get(line, 'color', layer.group_colors[index%N])


        #--- PLOT LINE ---
        l, = axes.plot( xdata, ydata,
                        linewidth=line.width,
                        linestyle=style,
                        marker=marker,
                        color=color)

        line_cache.append(l)
        omap[line] = l        

        label = self.get_line_label(line, table=table, cy=cy)
        l.set_label(label)
コード例 #14
0
    def draw_layer(self, layer, group_info):

        ax = self.layer_to_axes[layer]

        print "DRAWING AXES ", ax
        ax.lines = []

        line_cache = []
        line_count = 0
        last_cx = -1

        # Default values come in two flavors:
        # group-wise and single default values        
        group_colors = uwrap.get(layer, 'group_colors')
        group_styles = uwrap.get(layer, 'group_styles')
        group_markers = uwrap.get(layer, 'group_markers')

        #default_color = 'r'
        default_color = None
        default_style = 'solid'
        default_marker = 'None'
        

        #:layer.visible
        if uwrap.get(layer, 'visible') is False:
            return

        #:layer.title
        title = uwrap.get(layer, 'title', None)
        if title is not None:
            ax.set_title(title)        

        #:layer.grid
        grid = uwrap.get(layer, 'grid')
        ax.grid(grid)                         

        #:layer.lines
        for line in layer.lines:
            data_to_plot = []
            
            #:line.visible
            if uwrap.get(line, 'visible') is False:
                if line in ax.lines:
                    ax.lines.remove(line)
                continue

            ds = self.get_line_source(line)
            table = self.get_table(ds)
            cx, cy = self.get_column_indices(line)
            xdata, ydata = self.get_table_data(table, cx, cy)

            #:line.row_first
            #:line.row_last
            def limit_data(data, start, end):
                try:
                    return data[start:end]
                except IndexError:
                    backend.BackendError("Index range '%s'out of bounds!" % (start,end) )

            start, end = line.row_first, line.row_last
            xdata = limit_data(xdata, start, end)
            ydata = limit_data(ydata, start, end)
            

            #:line.style
            global linestyle_mappings
            default = default_style or group_styles[line_count % len(group_styles)]
            style = uwrap.get(line, 'style', default)
            style = linestyle_mappings[style]


            #:line.marker
            global linemarker_mappings
            default = default_marker or group_markers[line_count % len(group_markers)]
            marker = uwrap.get(line, 'marker', default)
            marker = linemarker_mappings[marker]


            #:line.width
            width = uwrap.get(line, 'width')

            
            #:line.color
            default = default_color or group_colors[line_count % len(group_colors)]
            color = uwrap.get(line, 'color', default)


            #--- PLOT LINE ---
            l, = ax.plot( xdata, ydata,
                          linewidth=width,
                          linestyle=style,
                          marker=marker,
                          color=color)
            line_cache.append(l)


            label = self.get_line_label(line, table=table, cy=cy)
            l.set_label(label)

            line_count += 1

#         #
#         # additional lines
#         #
#         p = len(xdata)
#         if p > 2: p = p/2
#         atpoint = xdata[max(p-1,0)]
#         print "Printing vertical line at ", atpoint
#         ax.axvline(atpoint)
        
        #:layer.legend
        legend = uwrap.get(layer, 'legend')
        if legend is not None and line_count > 0:
            visible = uwrap.get(legend, 'visible')
            if visible is True:
                #:legend.label:TODO
                label = uwrap.get(legend, 'visible')
                if label is not None:
                    pass

                #:legend.border:OK
                # (see below but keep it here!)
                border = uwrap.get(legend, 'border')
                                                
                #:legend.position TODO
                position = uwrap.get(legend, 'position', 'best')
                if position == 'at position':
                    position = (uwrap.get(legend, 'x'), uwrap.get(legend, 'y'))

                # create legend entries from line labels
                labels = [l.get_label() for l in line_cache]                
                
                legend = ax.legend(line_cache, labels, loc=position)
                legend.draw_frame(border)

            else:
                ax.legend_ = None
        else:
            ax.legend_ = None

        #:layer.axes
        for (key, axis) in layer.axes.iteritems():
            #:axis.label
            #:axis.scale
            #:axis.start
            #:axis.end
            label = uwrap.get(axis, 'label')            
            scale = uwrap.get(axis, 'scale')
            start = uwrap.get(axis, 'start')
            end = uwrap.get(axis, 'end')
            print "START = %s, END = %s" % (str(start), str(end))
            if key == 'x':
                set_label = ax.set_xlabel
                set_scale = ax.set_xscale
                set_start = (lambda l: ax.set_xlim(xmin=l))
                set_end = (lambda l: ax.set_xlim(xmax=l))
            elif key == 'y':
                set_label = ax.set_ylabel
                set_scale = ax.set_yscale
                set_start = (lambda l: ax.set_ylim(ymin=l))
                set_end = (lambda l: ax.set_ylim(ymax=l))
            else:
                raise RuntimeError("Invalid axis key '%s'" % key)

            if label is not None: set_label(label)
            if scale is not None: set_scale(scale)
            if start is not None: set_start(start)
            if end is not None: set_end(end)  
コード例 #15
0
    def draw_layer(self, layer, group_info):

        ax = self.layer_to_axes[layer]

        print "DRAWING AXES ", ax
        ax.lines = []

        line_cache = []
        line_count = 0
        last_cx = -1

        # Default values come in two flavors:
        # group-wise and single default values        
        group_colors = uwrap.get(layer, 'group_colors')
        group_styles = uwrap.get(layer, 'group_styles')
        group_markers = uwrap.get(layer, 'group_markers')

        #default_color = 'r'
        default_color = None
        default_style = 'solid'
        default_marker = 'None'
        

        #:layer.visible
        if uwrap.get(layer, 'visible') is False:
            return

        #:layer.title
        title = uwrap.get(layer, 'title', None)
        if title is not None:
            ax.set_title(title)        

        #:layer.grid
        grid = uwrap.get(layer, 'grid')
        ax.grid(grid)                         

        #:layer.lines
        for line in layer.lines:
            data_to_plot = []
            
            #:line.visible
            if uwrap.get(line, 'visible') is False:
                if line in ax.lines:
                    ax.lines.remove(line)
                continue

            #:line.source            
            if line.source is None:
                logger.warn("No Dataset specified for Line!")
                continue
            else:
                ds = line.source
                
            if ds.is_empty() is True:
                logger.warn("No data for Line!")
                continue

            table = ds.get_data()
            if not isinstance(table, Table):
                raise TypeError("Matplotlib Backend currently only supports data of type Table, while this is of %s"
                                % type(table))

            #:line.cx
            if line.cx is None or line.cy is None:
                logger.error("No x or y source given for Line. Line skipped.")
                continue
            else:
                cx, cy = line.cx, line.cy
            
            try:
                xdata = table[cx]
            except IndexError:
                logger.error("X-Index out of range (%s). Line skipped." % cx)
                continue


            #:line.cy
            try:
                ydata = table[cy]
            except IndexError:
                logger.error("Y-Index out of range (%s). Line skipped." % cy)
                continue


            #:line.style
            global linestyle_mappings
            default = default_style or group_styles[line_count % len(group_styles)]
            style = uwrap.get(line, 'style', default)
            style = linestyle_mappings[style]

            #:line.marker
            global linemarker_mappings
            default = default_marker or group_markers[line_count % len(group_markers)]
            marker = uwrap.get(line, 'marker', default)
            marker = linemarker_mappings[marker]

            #:line.width
            width = uwrap.get(line, 'width')
            
            #:line.color
            default = default_color or group_colors[line_count % len(group_colors)]
            color = uwrap.get(line, 'color', default)


            #--- PLOT LINE ---
            l, = ax.plot( xdata, ydata,
                          linewidth=width,
                          linestyle=style,
                          marker=marker,
                          color=color)
            line_cache.append(l)
            
            # TODO: if we set the label afterwards, don't we then have a redraw?
            #:line.label
            label = line.label
            if label is None:
                column = table.column(cy)
                label = column.label or column.key or uwrap.get(line, 'label')
            l.set_label(label)

            line_count += 1

#         #
#         # additional lines
#         #
#         p = len(xdata)
#         if p > 2: p = p/2
#         atpoint = xdata[max(p-1,0)]
#         print "Printing vertical line at ", atpoint
#         ax.axvline(atpoint)
        
        #:layer.legend
        legend = uwrap.get(layer, 'legend')
        if legend is not None and line_count > 0:
            visible = uwrap.get(legend, 'visible')
            if visible is True:
                #:legend.label TODO
                label = uwrap.get(legend, 'visible')
                if label is not None:
                    pass
                                
                #:legend.border TODO
                border = uwrap.get(legend, 'border')
                
                #:legend.position TODO
                position = uwrap.get(legend, 'position', 'best')
                if position == 'at position':
                    position = (uwrap.get(legend, 'x'), uwrap.get(legend, 'y'))

                # create legend entries from line labels
                labels = [l.get_label() for l in line_cache]
                ax.legend(line_cache, labels, loc=position)                
            else:
                ax.legend_ = None
        else:
            ax.legend_ = None

        #:layer.axes
        for (key, axis) in layer.axes.iteritems():
            #:axis.label
            #:axis.scale
            #:axis.start
            #:axis.end
            label = uwrap.get(axis, 'label')            
            scale = uwrap.get(axis, 'scale')
            start = uwrap.get(axis, 'start')
            end = uwrap.get(axis, 'end')
            print "START = %s, END = %s" % (str(start), str(end))
            if key == 'x':
                set_label = ax.set_xlabel
                set_scale = ax.set_xscale
                set_start = (lambda l: ax.set_xlim(xmin=l))
                set_end = (lambda l: ax.set_xlim(xmax=l))
            elif key == 'y':
                set_label = ax.set_ylabel
                set_scale = ax.set_yscale
                set_start = (lambda l: ax.set_ylim(ymin=l))
                set_end = (lambda l: ax.set_ylim(ymax=l))
            else:
                raise RuntimeError("Invalid axis key '%s'" % key)

            if label is not None: set_label(label)
            if scale is not None: set_scale(scale)
            if start is not None: set_start(start)
            if end is not None: set_end(end)  
コード例 #16
0
 def cb_project_closed(self, sender):
     logging.debug("The project '%s' is closing. The Backend will close as well." % uwrap.get(sender, 'label'))
     if self.connected is True:
         self.disconnect()
コード例 #17
0
    def build_layer(self, layer, group_info):
        """
        Returns a list of gnuplot commands that need to be executed
        to draw this layer.
        group_info is a dictionary containing information for grouped lines.        
        """

        rv = []

        # visible
        if uwrap.get(layer, 'visible') is False:
            return rv
        
        # title
        title = uwrap.get(layer, 'title')
        if title is not None: rv.append('set title "%s"' % title)
        else: rv.append("unset title")

        # grid
        grid = uwrap.get(layer, 'grid')
        if grid is True: rv.append('set grid')
        else: rv.append('unset grid')

        #:legend
        # (aka key in gnuplot)
        legend = uwrap.get(layer, 'legend')
        if legend is not None:
            #:legend.visible
            visible = uwrap.get(legend, 'visible')
            if visible is True:
                #:legend.label
                label = uwrap.get(legend, 'label')                
                if label is not None: key_title = 'title "%s"' % label
                else: key_title = ""

                #:legend.border:OK
                border = uwrap.get(legend, 'border')
                if border is True: key_border = "box"
                else: key_border = "nobox"

                # legend positioning
                position_mapping = {
                    'center' : 'graph 0.5, graph 0.5',
                    'lower left' : 'graph 0.0, graph 0.0',
                    'center right' : 'graph 1.0, graph 0.5',
                    'upper left' : 'graph 0.0, graph 1.0',
                    'center left' : 'graph 0.0, graph 0.5',
                    'upper right' : 'graph 1.0, graph 1.0',
                    'lower right' : 'graph 1.0, graph 0.0',
                    'upper center' : 'graph 0.5, graph 1.0',
                    'lower center' : 'graph 0.5, graph 0.0',
                    'outside' : 'outside'
                    }
                pos = uwrap.get(legend, 'position')
                if pos == 'best':
                    key_pos = ''
                elif pos == 'at position':
                    if legend.x is None and legend.y is None:
                        key_pos = ''
                    else:
                        x = uwrap.get(legend, 'x')
                        y = uwrap.get(legend, 'y')
                        key_pos = 'graph %.2f, graph %.2f' % (x, y)
                else:
                    key_pos = position_mapping[pos]

                rv.append("set key %(key_pos)s %(key_title)s %(key_border)s" % locals())
            else:
                rv.append("unset key")                

        # axes
        for key, axis in layer.axes.iteritems():            
            # axis format
            format = uwrap.get(axis, 'format')
            if format is not None: rv.append('set format %s "%s"' % (key, format))
            else: rv.append('set format %s' % key)

            # axis label
            label = uwrap.get(axis, 'label')
            if label is not None: rv.append('set %slabel "%s"' % (key, label))
            else: rv.append('unset %slabel' % key)

            # axis range
            start = uwrap.get(axis, 'start','*')
            end = uwrap.get(axis, 'end','*')
            rv.append('set %srange [%s:%s]' % (key,start,end))

            # axis scale
            scale = uwrap.get(axis, 'scale')
            if scale == 'linear': rv.append('unset log %s' % key)
            elif scale == 'log': rv.append('set log %s' % key)
            else:
                logger.error("Axis scale '%s' not supported by this backend." % scale)

        #:layer.labels
        for label in layer.labels:                                    
            if label.system == 0: # 0: data
                coords = "at first %.2f, first %.2f" % (label.x, label.y)
            elif label.system == 1: # 1: graph
                coords = "at graph %.2f, graph %.2f" % (label.x, label.y)

            map_align = {0:'center', 1:'left', 2:'right'}
            align = map_align[label.halign]
            rv.append('set label "%s" %s %s' % (label.text, coords, align) )


        # lines
        line_cache = []
        for line in layer.lines:
            try:
                if uwrap.get(line, 'visible') is False: continue

                ds = self.get_line_source(line)
                table = self.get_table(ds)
                cx, cy = self.get_column_indices(line)
                
                # mark source for export            
                filename = self.mark_for_export(ds)
                if filename is None:
                    continue
                source = '"%s"' % filename

                label = self.get_line_label(line, table=table, cy=cy)
                if label is not None: title = 'title "%s"' % label
                else: title = 'notitle'

                using = 'using %s:%s' % (cx+1,cy+1)

                # TODO: support 'style' and 'marker'
                # with-clause
                type = uwrap.get(line, 'style')
                type_mappings = {'solid': 'w l'}
                try:
                    with = type_mappings[type]
                except KeyError:
                    with = ''
                    logger.error('line type "%s" not supported by this backend.' % type )

                # line width
                width = uwrap.get(line, 'width')
                width = 'lw %s' % str(width)
コード例 #18
0
    def update_layer(self, layer, updateinfo={}):
        # updateinfo is ignored

        self.omaps[layer] = {}
        self.line_caches[layer] = {}

        axes = self.layer_to_axes[layer]        
        axes.lines = []
        line_cache = self.line_caches[layer] = []        

        #:layer.lines:OK
        for line in layer.lines:
            self.update_line(line, layer, axes=axes)

        #:layer.axes
        for (key, axis) in layer.axes.iteritems():
            #:axis.label
            #:axis.scale
            #:axis.start
            #:axis.end
            label = uwrap.get(axis, 'label')            
            scale = uwrap.get(axis, 'scale')
            start = uwrap.get(axis, 'start')
            end = uwrap.get(axis, 'end')

            logger.debug("start = %s; end = %s" % (start, end))
            
            if key == 'x':
                set_label = axes.set_xlabel
                set_scale = axes.set_xscale
                set_start = (lambda l: axes.set_xlim(xmin=l))
                set_end = (lambda l: axes.set_xlim(xmax=l))
            elif key == 'y':
                set_label = axes.set_ylabel
                set_scale = axes.set_yscale
                set_start = (lambda l: axes.set_ylim(ymin=l))
                set_end = (lambda l: axes.set_ylim(ymax=l))
            else:
                raise RuntimeError("Invalid axis key '%s'" % key)

            if label is not None: set_label(label)
            if scale is not None: set_scale(scale)
            if start is not None: set_start(start)
            if end is not None: set_end(end)
            
        #:layer.visible
        if uwrap.get(layer, 'visible') is False:
            return

        # TODO
        #:layer.title
        title = uwrap.get(layer, 'title', None)
        if title is not None:
            axes.set_title(title)

        #:layer.grid
        grid = uwrap.get(layer, 'grid', None)        
        axes.grid(grid)
                    
        #:layer.legend:OK
        self.update_legend(layer)

        #:layer.labels:OK
        axes.texts = []
        for label in layer.labels:
            self.update_textlabel(label, layer)
コード例 #19
0
    def draw_layer(self, layer, group_info):

        ax = self.layer_to_axes[layer]
        logger.info ("drawing layer %s (axes %s)" % (layer, ax))

        omap = self.omaps[layer]
        
        ax.lines = []

        line_cache = self.line_caches[layer] = []
        last_cx = -1

        # Default values come in two flavors:
        # group-wise and single default values        
        group_styles = uwrap.get(layer, 'group_styles')
        group_markers = uwrap.get(layer, 'group_markers')        


   # def update_layer(self, layer):

        #:layer.axes
        for (key, axis) in layer.axes.iteritems():
            #:axis.label
            #:axis.scale
            #:axis.start
            #:axis.end
            label = uwrap.get(axis, 'label')            
            scale = uwrap.get(axis, 'scale')
            start = uwrap.get(axis, 'start')
            end = uwrap.get(axis, 'end')
            print "START = %s, END = %s" % (str(start), str(end))
            if key == 'x':
                set_label = ax.set_xlabel
                set_scale = ax.set_xscale
                set_start = (lambda l: ax.set_xlim(xmin=l))
                set_end = (lambda l: ax.set_xlim(xmax=l))
            elif key == 'y':
                set_label = ax.set_ylabel
                set_scale = ax.set_yscale
                set_start = (lambda l: ax.set_ylim(ymin=l))
                set_end = (lambda l: ax.set_ylim(ymax=l))
            else:
                raise RuntimeError("Invalid axis key '%s'" % key)

            if label is not None: set_label(label)
            if scale is not None: set_scale(scale)
            if start is not None: set_start(start)
            if end is not None: set_end(end)

            
        #:layer.visible
        if uwrap.get(layer, 'visible') is False:
            return

        # TODO
        #:layer.title
        title = uwrap.get(layer, 'title', None)
        if title is not None:
            ax.set_title(title)        

        # TODO
        #:layer.grid
        grid = uwrap.get(layer, 'grid')        
        ax.grid(grid)                         

        #:layer.lines:OK
        for line in layer.lines:
            self.update_line(line, layer, axes=ax)
                    
        #:layer.legend:OK
        self.update_legend(layer.legend, layer)

        #:layer.labels:OK
        ax.texts = []
        for label in layer.labels:
            self.update_textlabel(label, layer)