Exemplo n.º 1
0
    def __init__(self, data, ax, prefs, *args, **kw):

        PlotBase.__init__(self, data, ax, prefs, *args, **kw)
        if type(data) == types.DictType:
            self.gdata = GraphData(data)
        elif type(data) == types.InstanceType and data.__class__ == GraphData:
            self.gdata = data
        if self.prefs.has_key('span'):
            self.width = self.prefs['span']
        else:
            self.width = 1.0
            if self.gdata.key_type == "time":
                nKeys = self.gdata.getNumberOfKeys()
                self.width = (max(self.gdata.all_keys) -
                              min(self.gdata.all_keys)) / nKeys

        # Setup the colormapper to get the right colors
        self.cmap = LinearSegmentedColormap('quality_colormap', cdict, 256)
        #self.cmap = cm.RdYlGn
        self.norms = normalize(0, 100)
        mapper = cm.ScalarMappable(cmap=self.cmap, norm=self.norms)
        mapper = cm.ScalarMappable(cmap=cm.RdYlGn, norm=self.norms)

        def get_alpha(*args, **kw):
            return 1.0

        mapper.get_alpha = get_alpha
        self.mapper = mapper
Exemplo n.º 2
0
    def __init__(self, data, ax, prefs, *args, **kw):

        PlotBase.__init__(self, data, ax, prefs, *args, **kw)
        if type(data) == types.DictType:
            self.gdata = GraphData(data)
        elif type(data) == types.InstanceType and data.__class__ == GraphData:
            self.gdata = data
        if self.prefs.has_key('span'):
            self.width = self.prefs['span']
        else:
            self.width = 1.0
            if self.gdata.key_type == "time":
                nKeys = self.gdata.getNumberOfKeys()
                self.width = (max(self.gdata.all_keys) -
                              min(self.gdata.all_keys)) / nKeys

        # Setup the colormapper to get the right colors
        self.cmap = None

        max_value = prefs.get('normalization')
        if max_value:
            self.cmap = cm.YlGnBu
        else:
            max_value = 100
            self.cmap = cm.RdYlGn

        self.norms = Normalize(0, max_value)
        mapper = cm.ScalarMappable(cmap=self.cmap, norm=self.norms)

        def get_alpha(*args, **kw):
            return 1.0

        mapper.get_alpha = get_alpha
        self.mapper = mapper
Exemplo n.º 3
0
    def __init__(self, data, ax, prefs, *args, **kw):

        PlotBase.__init__(self, data, ax, prefs, *args, **kw)
        if isinstance(data, dict):
            self.gdata = GraphData(data)
        elif isinstance(data, type) and data.__class__ == GraphData:
            self.gdata = data
        if "span" in self.prefs:
            self.width = self.prefs["span"]
        else:
            self.width = 1.0
            if self.gdata.key_type == "time":
                nKeys = self.gdata.getNumberOfKeys()
                self.width = (max(self.gdata.all_keys) -
                              min(self.gdata.all_keys)) / nKeys

        # redefine the look of the scale if requested
        if isinstance(self.prefs["scale_data"], dict):
            self.cbBoundaries = list()
            self.cbValues = list()

            # ColorbarBase needs sorted data
            for boundary in sorted(self.prefs["scale_data"]):
                self.cbBoundaries.append(boundary)
                self.cbValues.append(self.prefs["scale_data"][boundary])
        else:
            self.cbBoundaries = None  # set default values
            self.cbValues = None

        if isinstance(self.prefs["scale_ticks"], list):
            self.cbTicks = self.prefs["scale_ticks"]
        else:
            self.cbTicks = None  # set default value

        # Setup the colormapper to get the right colors
        self.cmap = None

        max_value = prefs.get("normalization")
        if max_value:
            self.cmap = cm.YlGnBu  # pylint: disable=no-member
        else:
            max_value = 100
            self.cmap = cm.RdYlGn  # pylint: disable=no-member

        self.norms = Normalize(0, max_value)
        mapper = cm.ScalarMappable(cmap=self.cmap, norm=self.norms)

        def get_alpha(*args, **kw):
            return 1.0

        mapper.get_alpha = get_alpha
        self.mapper = mapper
Exemplo n.º 4
0
    def __init__(self, data=None, axes=None, *aw, **kw):

        self.ax_contain = axes
        self.canvas = None
        self.figure = None
        if self.ax_contain:
            self.figure = self.ax_contain.get_figure()
            self.canvas = self.figure.canvas
            self.dpi = self.ax_contain.figure.get_dpi()
            self.ax_contain.set_axis_off()
        self.prefs = evalPrefs(*aw, **kw)
        self.coords = {}
        self.palette = Palette()
        if isinstance(data, dict):
            self.gdata = GraphData(data)
        elif isinstance(data, object) and data.__class__ == GraphData:
            self.gdata = data
Exemplo n.º 5
0
    def makeGraph(self, data, *args, **kw):

        start = time.time()

        # Evaluate all the preferences
        self.prefs = evalPrefs(*args, **kw)
        prefs = self.prefs

        if DEBUG:
            print "makeGraph time 1", time.time() - start
            start = time.time()

        if prefs.has_key('text_image'):
            self.makeTextGraph(str(prefs['text_image']))
            return

        # Evaluate the number of plots and their requested layout
        metadata = prefs.get('metadata', {})
        plot_grid = prefs.get('plot_grid', '1:1')
        nx = int(plot_grid.split(':')[0])
        ny = int(plot_grid.split(':')[1])
        nPlots = nx * ny
        if nPlots == 1:
            if not isinstance(data, list):
                data = [data]
            if not isinstance(metadata, list):
                metadata = [metadata]
        else:
            if not isinstance(data, list):
                #return S_ERROR('Single data for multiplot graph')
                print 'Single data for multiplot graph'
                return
            if not isinstance(metadata, list):
                metaList = []
                for _ in range(nPlots):
                    metaList.append(metadata)
                metadata = metaList

        # Initialize plot data
        graphData = []
        plot_prefs = []
        for i in range(nPlots):
            plot_prefs.append(evalPrefs(prefs, metadata[i]))
            gdata = GraphData(data[i])
            if i == 0: plot_type = plot_prefs[i]['plot_type']
            if plot_prefs[i].has_key('sort_labels'):
                reverse = plot_prefs[i].get('reverse_labels', False)
                gdata.sortLabels(plot_prefs[i]['sort_labels'],
                                 reverse_order=reverse)
            if plot_prefs[i].has_key('limit_labels'):
                if plot_prefs[i]['limit_labels'] > 0:
                    gdata.truncateLabels(plot_prefs[i]['limit_labels'])
            if plot_prefs[i].has_key('cumulate_data'):
                gdata.makeCumulativeGraph()
            plot_title = plot_prefs[i].get('plot_title', '')
            if plot_title != "NoTitle":
                begin = ''
                end = ''
                if plot_prefs[i].has_key(
                        'starttime') and plot_prefs[i].has_key('endtime'):
                    begin = to_timestamp(plot_prefs[i]['starttime'])
                    end = to_timestamp(plot_prefs[i]['endtime'])
                elif gdata.key_type == "time":
                    begin = gdata.min_key
                    end = gdata.max_key
                if begin and end:
                    time_title = add_time_to_title(begin, end)
                    if plot_title:
                        plot_title += ":"
                    plot_prefs[i]['plot_title'] = plot_title + ' ' + time_title
            graphData.append(gdata)

        # Do not make legend for the plot with non-string keys (except for PieGraphs)
        if not graphData[0].subplots and graphData[
                0].key_type != 'string' and not plot_type == 'PieGraph':
            prefs['legend'] = False
        if prefs['legend'] and graphData[
                0].key_type != 'string' and plot_type == 'PieGraph':
            graphData[0].initialize(key_type='string')

        legend = Legend(graphData[0], None, prefs)
        self.figure = Figure()

        # Make Water Mark
        image = prefs.get('watermark', None)
        self.drawWaterMark(image)

        legend_ax, plot_axes = self.layoutFigure(legend)

        if DEBUG:
            print "makeGraph time layout", time.time() - start
            start = time.time()

        # Make plots
        for i in range(nPlots):
            plot_type = plot_prefs[i]['plot_type']
            try:
                exec "import %s" % plot_type
            except ImportError, x:
                print "Failed to import graph type %s: %s" % (plot_type,
                                                              str(x))
                return None

            ax = plot_axes[i]
            plot = eval("%s.%s(graphData[i],ax,plot_prefs[i])" %
                        (plot_type, plot_type))
            plot.draw()
Exemplo n.º 6
0
    def makeGraph(self, data, *args, **kw):

        start = time.time()

        # Evaluate all the preferences
        self.prefs = evalPrefs(*args, **kw)
        prefs = self.prefs

        if DEBUG:
            print("makeGraph time 1", time.time() - start)
            start = time.time()

        if "text_image" in prefs:
            self.makeTextGraph(str(prefs["text_image"]))
            return

        # Evaluate the number of plots and their requested layout
        metadata = prefs.get("metadata", {})
        plot_grid = prefs.get("plot_grid", "1:1")
        nx = int(plot_grid.split(":")[0])
        ny = int(plot_grid.split(":")[1])
        nPlots = nx * ny
        if nPlots == 1:
            if not isinstance(data, list):
                data = [data]
            if not isinstance(metadata, list):
                metadata = [metadata]
        else:
            if not isinstance(data, list):
                # return S_ERROR('Single data for multiplot graph')
                print("Single data for multiplot graph")
                return
            if not isinstance(metadata, list):
                metaList = []
                for _ in range(nPlots):
                    metaList.append(metadata)
                metadata = metaList

        # Initialize plot data
        graphData = []
        plot_prefs = []
        for i in range(nPlots):
            plot_prefs.append(evalPrefs(prefs, metadata[i]))
            gdata = GraphData(data[i])
            if i == 0:
                plot_type = plot_prefs[i]["plot_type"]
            if "sort_labels" in plot_prefs[i]:
                reverse = plot_prefs[i].get("reverse_labels", False)
                gdata.sortLabels(plot_prefs[i]["sort_labels"],
                                 reverse_order=reverse)
            if "limit_labels" in plot_prefs[i]:
                if plot_prefs[i]["limit_labels"] > 0:
                    gdata.truncateLabels(plot_prefs[i]["limit_labels"])
            if "cumulate_data" in plot_prefs[i]:
                gdata.makeCumulativeGraph()
            plot_title = plot_prefs[i].get("plot_title", "")
            if plot_title != "NoTitle":
                begin = ""
                end = ""
                if "starttime" in plot_prefs[i] and "endtime" in plot_prefs[i]:
                    begin = to_timestamp(plot_prefs[i]["starttime"])
                    end = to_timestamp(plot_prefs[i]["endtime"])
                elif gdata.key_type == "time":
                    begin = gdata.min_key
                    end = gdata.max_key
                if begin and end:
                    time_title = add_time_to_title(begin, end)
                    if plot_title:
                        plot_title += ":"
                    plot_prefs[i]["plot_title"] = plot_title + " " + time_title
            graphData.append(gdata)

        # Do not make legend for the plot with non-string keys (except for PieGraphs)
        if not graphData[0].subplots and graphData[
                0].key_type != "string" and not plot_type == "PieGraph":
            prefs["legend"] = False
        if prefs["legend"] and graphData[
                0].key_type != "string" and plot_type == "PieGraph":
            graphData[0].initialize(key_type="string")

        legend = Legend(graphData[0], None, prefs)
        self.figure = Figure()

        # Make Water Mark
        image = prefs.get("watermark", None)
        self.drawWaterMark(image)

        legend_ax, plot_axes = self.layoutFigure(legend)

        if DEBUG:
            print("makeGraph time layout", time.time() - start)
            start = time.time()

        # Make plots
        for i in range(nPlots):
            plot_type = plot_prefs[i]["plot_type"]
            try:
                # TODO: Remove when we moved to python3
                exec("import %s" % plot_type)
            except ImportError:
                print("Trying to use python like import")
                try:
                    exec("from . import  %s" % plot_type)
                except ImportError as x:
                    print("Failed to import graph type %s: %s" %
                          (plot_type, str(x)))
                    return None

            ax = plot_axes[i]
            plot = eval("%s.%s(graphData[i],ax,plot_prefs[i])" %
                        (plot_type, plot_type))
            plot.draw()

        if DEBUG:
            print("makeGraph time plots", time.time() - start)
            start = time.time()

        # Make legend
        if legend_ax:
            legend.setAxes(legend_ax)
            legend.draw()

        if DEBUG:
            print("makeGraph time legend", time.time() - start)
            start = time.time()