Exemplo n.º 1
0
    def makeTextGraph(self, text="Empty image"):
        """ Make an empty text image
    """

        self.figure = Figure()
        figure = self.figure
        self.canvas = FigureCanvasAgg(figure)

        prefs = self.prefs
        dpi = prefs["dpi"]
        width = float(prefs["width"])
        height = float(prefs["height"])
        width_inch = width / dpi
        height_inch = height / dpi
        figure.set_size_inches(width_inch, height_inch)
        figure.set_dpi(dpi)
        figure.set_facecolor("white")

        text_size = prefs.get("text_size", 12)
        figure.text(0.5, 0.5, text, horizontalalignment="center", size=pixelToPoint(text_size, dpi))
Exemplo n.º 2
0
  def makeTextGraph(self, text='Empty image'):
    """ Make an empty text image
    """

    self.figure = Figure()
    figure = self.figure
    self.canvas = FigureCanvasAgg(figure)

    prefs = self.prefs
    dpi = prefs['dpi']
    width = float(prefs['width'])
    height = float(prefs['height'])
    width_inch = width/dpi
    height_inch = height/dpi
    figure.set_size_inches( width_inch, height_inch )
    figure.set_dpi( dpi )
    figure.set_facecolor('white')

    text_size = prefs.get('text_size',12)
    figure.text( .5, .5, text, horizontalalignment='center',
                 size=pixelToPoint(text_size,dpi) )
Exemplo n.º 3
0
    def makeTextGraph(self, text="Empty image"):
        """Make an empty text image"""

        self.figure = Figure()
        figure = self.figure
        self.canvas = FigureCanvasAgg(figure)

        prefs = self.prefs
        dpi = prefs["dpi"]
        width = float(prefs["width"])
        height = float(prefs["height"])
        width_inch = width / dpi
        height_inch = height / dpi
        figure.set_size_inches(width_inch, height_inch)
        figure.set_dpi(dpi)
        figure.set_facecolor("white")

        text_size = prefs.get("text_size", 12)
        figure.text(0.5,
                    0.5,
                    text,
                    horizontalalignment="center",
                    size=pixelToPoint(text_size, dpi))
Exemplo n.º 4
0
    def makeTextGraph(self, text='Empty image'):
        """ Make an empty text image
    """

        self.figure = Figure()
        figure = self.figure
        self.canvas = FigureCanvasAgg(figure)

        prefs = self.prefs
        dpi = prefs['dpi']
        width = float(prefs['width'])
        height = float(prefs['height'])
        width_inch = width / dpi
        height_inch = height / dpi
        figure.set_size_inches(width_inch, height_inch)
        figure.set_dpi(dpi)
        figure.set_facecolor('white')

        text_size = prefs.get('text_size', 12)
        figure.text(.5,
                    .5,
                    text,
                    horizontalalignment='center',
                    size=pixelToPoint(text_size, dpi))
Exemplo n.º 5
0
  def layoutFigure(self,legend):

    prefs = self.prefs

    # Get the main Figure object
    #self.figure = Figure()
    figure = self.figure
    self.canvas = FigureCanvasAgg(figure)

    dpi = prefs['dpi']
    width = float(prefs['width'])
    height = float(prefs['height'])
    width_inch = width/dpi
    height_inch = height/dpi
    figure.set_size_inches( width_inch, height_inch )
    figure.set_dpi( dpi )
    figure.set_facecolor(prefs.get('background_color','white'))

    figure_padding = float(prefs['figure_padding'])
    figure_left_padding = float(prefs.get('figure_left_padding',figure_padding))
    figure_right_padding = float(prefs.get('figure_right_padding',figure_padding))
    figure_top_padding = float(prefs.get('figure_top_padding',figure_padding))
    figure_bottom_padding = float(prefs.get('figure_bottom_padding',figure_padding))

    text_size = prefs.get('text_size',8)
    text_padding = prefs.get('text_padding',5)

    #######################################
    # Make the graph title

    title = prefs.get('title','')
    subtitle = ''
    title_size = 0
    title_padding = 0
    if title:
      title_size = prefs.get('title_size',1.5*text_size)
      title_padding = float(prefs.get('title_padding',1.5*text_padding))
      figure.text(0.5,1.-(title_size+figure_padding)/height,title,
                  ha='center',va='bottom',size=pixelToPoint(title_size,dpi) )

      subtitle = prefs.get('subtitle','')
      if subtitle:
        sublines = subtitle.split('\n')
        nsublines = len(sublines)
        subtitle_size = prefs.get('subtitle_size',1.2*text_size)
        subtitle_padding = float(prefs.get('subtitle_padding',1.2*text_padding))
        top_offset = subtitle_size+subtitle_padding+title_size+figure_padding
        for subline in sublines:
          figure.text(0.5,1.-(top_offset)/height,
                      subline,ha='center',va='bottom',
                      size=pixelToPoint(subtitle_size,dpi),fontstyle='italic' )
          top_offset +=  subtitle_size + subtitle_padding

    ########################################
    # Evaluate the plot area dimensions
    graph_width = width - figure_left_padding - figure_right_padding
    graph_height = height - figure_top_padding - figure_bottom_padding
    if title:
      graph_height = graph_height - title_padding - title_size
    if subtitle:
      graph_height = graph_height - nsublines*(subtitle_size + subtitle_padding)
    graph_left = figure_left_padding
    graph_bottom = figure_bottom_padding

    #########################################
    # Make the plot time stamp if requested
    flag = prefs.get('graph_time_stamp',True)
    if flag:
      timeString = "Generated on " + \
                   datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S ')+'UTC'
      time_size = prefs['text_size']*.8
      figure.text(0.995,0.005,timeString,ha='right',va='bottom',size=pixelToPoint(time_size,dpi),fontstyle='italic' )

    #########################################
    # Make the graph Legend if requested

    legend_flag = prefs['legend']
    legend_ax = None
    column_width = legend.column_width
    if legend_flag:
      legend_position = prefs['legend_position']
      #legend_width = float(prefs['legend_width'])
      #legend_height = float(prefs['legend_height'])
      legend_width,legend_height,legend_max_height = legend.getLegendSize()
      legend_padding = float(prefs['legend_padding'])
      if legend_position in ['right','left']:
        # One column in case of vertical legend
        legend_width = column_width+legend_padding
        legend_height = min(graph_height,legend_max_height)
        bottom = (height-title_size-title_padding-legend_height)/2./height
        if legend_position == 'right':
          left = 1. - (figure_padding+legend_width)/width
        else:
          left = figure_padding/width
          graph_left = graph_left + legend_width
        graph_width = graph_width - legend_width - legend_padding
      elif legend_position == 'bottom':
        bottom = figure_padding/height
        left = (width-legend_width)/2./width
        graph_height = graph_height  - legend_height - legend_padding
        graph_bottom = graph_bottom + legend_height + legend_padding

      legend_rect = (left,bottom,legend_width/width,legend_height/height)
      legend_ax = figure.add_axes(legend_rect)

    ###########################################
    # Make the plot spots
    plot_grid = prefs['plot_grid']
    nx = int(plot_grid.split(':')[0])
    ny = int(plot_grid.split(':')[1])

    plot_axes = []
    for j in range(ny-1,-1,-1):
      for i in range(nx):
        plot_rect = ((graph_left+graph_width*i/nx)/width,
                     (graph_bottom+graph_height*j/ny)/height,
                     graph_width/nx/width,
                     graph_height/ny/height)

        plot_axes.append(figure.add_axes(plot_rect))

    return legend_ax, plot_axes
Exemplo n.º 6
0
    def layoutFigure(self, legend):

        prefs = self.prefs

        # Get the main Figure object
        #self.figure = Figure()
        figure = self.figure
        self.canvas = FigureCanvasAgg(figure)

        dpi = prefs['dpi']
        width = float(prefs['width'])
        height = float(prefs['height'])
        width_inch = width / dpi
        height_inch = height / dpi
        figure.set_size_inches(width_inch, height_inch)
        figure.set_dpi(dpi)
        figure.set_facecolor(prefs.get('background_color', 'white'))

        figure_padding = float(prefs['figure_padding'])
        figure_left_padding = float(
            prefs.get('figure_left_padding', figure_padding))
        figure_right_padding = float(
            prefs.get('figure_right_padding', figure_padding))
        figure_top_padding = float(
            prefs.get('figure_top_padding', figure_padding))
        figure_bottom_padding = float(
            prefs.get('figure_bottom_padding', figure_padding))

        text_size = prefs.get('text_size', 8)
        text_padding = prefs.get('text_padding', 5)

        #######################################
        # Make the graph title

        title = prefs.get('title', '')
        subtitle = ''
        title_size = 0
        title_padding = 0
        if title:
            title_size = prefs.get('title_size', 1.5 * text_size)
            title_padding = float(
                prefs.get('title_padding', 1.5 * text_padding))
            figure.text(0.5,
                        1. - (title_size + figure_padding) / height,
                        title,
                        ha='center',
                        va='bottom',
                        size=pixelToPoint(title_size, dpi))

            subtitle = prefs.get('subtitle', '')
            if subtitle:
                sublines = subtitle.split('\n')
                nsublines = len(sublines)
                subtitle_size = prefs.get('subtitle_size', 1.2 * text_size)
                subtitle_padding = float(
                    prefs.get('subtitle_padding', 1.2 * text_padding))
                top_offset = subtitle_size + subtitle_padding + title_size + figure_padding
                for subline in sublines:
                    figure.text(0.5,
                                1. - (top_offset) / height,
                                subline,
                                ha='center',
                                va='bottom',
                                size=pixelToPoint(subtitle_size, dpi),
                                fontstyle='italic')
                    top_offset += subtitle_size + subtitle_padding

        ########################################
        # Evaluate the plot area dimensions
        graph_width = width - figure_left_padding - figure_right_padding
        graph_height = height - figure_top_padding - figure_bottom_padding
        if title:
            graph_height = graph_height - title_padding - title_size
        if subtitle:
            graph_height = graph_height - nsublines * (subtitle_size +
                                                       subtitle_padding)
        graph_left = figure_left_padding
        graph_bottom = figure_bottom_padding

        #########################################
        # Make the plot time stamp if requested
        flag = prefs.get('graph_time_stamp', True)
        if flag:
            timeString = "Generated on " + \
                         datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S ')+'UTC'
            time_size = prefs['text_size'] * .8
            figure.text(0.995,
                        0.005,
                        timeString,
                        ha='right',
                        va='bottom',
                        size=pixelToPoint(time_size, dpi),
                        fontstyle='italic')

        #########################################
        # Make the graph Legend if requested

        legend_flag = prefs['legend']
        legend_ax = None
        column_width = legend.column_width
        if legend_flag:
            legend_position = prefs['legend_position']
            #legend_width = float(prefs['legend_width'])
            #legend_height = float(prefs['legend_height'])
            legend_width, legend_height, legend_max_height = legend.getLegendSize(
            )
            legend_padding = float(prefs['legend_padding'])
            if legend_position in ['right', 'left']:
                # One column in case of vertical legend
                legend_width = column_width + legend_padding
                legend_height = min(graph_height, legend_max_height)
                bottom = (height - title_size - title_padding -
                          legend_height) / 2. / height
                if legend_position == 'right':
                    left = 1. - (figure_padding + legend_width) / width
                else:
                    left = figure_padding / width
                    graph_left = graph_left + legend_width
                graph_width = graph_width - legend_width - legend_padding
            elif legend_position == 'bottom':
                bottom = figure_padding / height
                left = (width - legend_width) / 2. / width
                graph_height = graph_height - legend_height - legend_padding
                graph_bottom = graph_bottom + legend_height + legend_padding

            legend_rect = (left, bottom, legend_width / width,
                           legend_height / height)
            legend_ax = figure.add_axes(legend_rect)

        ###########################################
        # Make the plot spots
        plot_grid = prefs['plot_grid']
        nx = int(plot_grid.split(':')[0])
        ny = int(plot_grid.split(':')[1])

        plot_axes = []
        for j in range(ny - 1, -1, -1):
            for i in range(nx):
                plot_rect = ((graph_left + graph_width * i / nx) / width,
                             (graph_bottom + graph_height * j / ny) / height,
                             graph_width / nx / width,
                             graph_height / ny / height)

                plot_axes.append(figure.add_axes(plot_rect))

        return legend_ax, plot_axes
Exemplo n.º 7
0
    def draw(self):

        PlotBase.draw(self)
        self.x_formatter_cb(self.ax)

        if self.gdata.isEmpty():
            return None

        # Evaluate the bar width
        width = float(self.width)
        offset = 0.0
        if self.gdata.key_type == "time":
            width = width / 86400.0

        start_plot = 0
        end_plot = 0
        if "starttime" in self.prefs and "endtime" in self.prefs:
            start_plot = date2num(
                datetime.datetime.fromtimestamp(
                    to_timestamp(self.prefs["starttime"])))
            end_plot = date2num(
                datetime.datetime.fromtimestamp(
                    to_timestamp(self.prefs["endtime"])))

        labels = self.gdata.getLabels()
        nKeys = self.gdata.getNumberOfKeys()
        tmp_b = []
        tmp_x = []
        tmp_y = []

        self.bars = []
        labels = self.gdata.getLabels()
        nLabel = 0
        labelNames = []
        colors = []
        xmin = None
        xmax = None
        for label, _num in labels:
            labelNames.append(label)
            for key, value, _error in self.gdata.getPlotNumData(label):

                if xmin is None or xmin > (key + offset):
                    xmin = key + offset
                if xmax is None or xmax < (key + offset):
                    xmax = key + offset

                if value is not None:
                    colors.append(self.getQualityColor(value))
                    tmp_x.append(key + offset)
                    tmp_y.append(1.0)
                    tmp_b.append(float(nLabel))

            nLabel += 1

        self.bars += self.ax.bar(tmp_x,
                                 tmp_y,
                                 bottom=tmp_b,
                                 width=width,
                                 color=colors)

        dpi = self.prefs.get("dpi", 100)
        setp(self.bars, linewidth=pixelToPoint(0.5, dpi), edgecolor="#AAAAAA")

        # pivots = keys
        # for idx in range(len(pivots)):
        #    self.coords[ pivots[idx] ] = self.bars[idx]

        ymax = float(nLabel)
        self.ax.set_xlim(xmin=0.0, xmax=xmax + width + offset)
        self.ax.set_ylim(ymin=0.0, ymax=ymax)
        if self.gdata.key_type == "time":
            if start_plot and end_plot:
                self.ax.set_xlim(xmin=start_plot, xmax=end_plot)
            else:
                self.ax.set_xlim(xmin=min(tmp_x), xmax=max(tmp_x))
        self.ax.set_yticks([i + 0.5 for i in range(nLabel)])
        self.ax.set_yticklabels(labelNames)
        setp(self.ax.get_xticklines(), markersize=0.0)
        setp(self.ax.get_yticklines(), markersize=0.0)

        cax, kw = make_axes(self.ax, orientation="vertical", fraction=0.07)
        cb = ColorbarBase(cax,
                          cmap=self.cmap,
                          norm=self.norms,
                          boundaries=self.cbBoundaries,
                          values=self.cbValues,
                          ticks=self.cbTicks)
        cb.draw_all()
Exemplo n.º 8
0
    def layoutFigure(self, legend):

        prefs = self.prefs

        # Get the main Figure object
        # self.figure = Figure()
        figure = self.figure
        self.canvas = FigureCanvasAgg(figure)

        dpi = prefs["dpi"]
        width = float(prefs["width"])
        height = float(prefs["height"])
        width_inch = width / dpi
        height_inch = height / dpi
        figure.set_size_inches(width_inch, height_inch)
        figure.set_dpi(dpi)
        figure.set_facecolor(prefs.get("background_color", "white"))

        figure_padding = float(prefs["figure_padding"])
        figure_left_padding = float(prefs.get("figure_left_padding", figure_padding))
        figure_right_padding = float(prefs.get("figure_right_padding", figure_padding))
        figure_top_padding = float(prefs.get("figure_top_padding", figure_padding))
        figure_bottom_padding = float(prefs.get("figure_bottom_padding", figure_padding))

        text_size = prefs.get("text_size", 8)
        text_padding = prefs.get("text_padding", 5)

        #######################################
        # Make the graph title

        title = prefs.get("title", "")
        subtitle = ""
        title_size = 0
        title_padding = 0
        if title:
            title_size = prefs.get("title_size", 1.5 * text_size)
            title_padding = float(prefs.get("title_padding", 1.5 * text_padding))
            figure.text(
                0.5,
                1.0 - (title_size + figure_padding) / height,
                title,
                ha="center",
                va="bottom",
                size=pixelToPoint(title_size, dpi),
            )

            subtitle = prefs.get("subtitle", "")
            if subtitle:
                sublines = subtitle.split("\n")
                nsublines = len(sublines)
                subtitle_size = prefs.get("subtitle_size", 1.2 * text_size)
                subtitle_padding = float(prefs.get("subtitle_padding", 1.2 * text_padding))
                top_offset = subtitle_size + subtitle_padding + title_size + figure_padding
                for subline in sublines:
                    figure.text(
                        0.5,
                        1.0 - (top_offset) / height,
                        subline,
                        ha="center",
                        va="bottom",
                        size=pixelToPoint(subtitle_size, dpi),
                        fontstyle="italic",
                    )
                    top_offset += subtitle_size + subtitle_padding

        ########################################
        # Evaluate the plot area dimensions
        graph_width = width - figure_left_padding - figure_right_padding
        graph_height = height - figure_top_padding - figure_bottom_padding
        if title:
            graph_height = graph_height - title_padding - title_size
        if subtitle:
            graph_height = graph_height - nsublines * (subtitle_size + subtitle_padding)
        graph_left = figure_left_padding
        graph_bottom = figure_bottom_padding

        #########################################
        # Make the plot time stamp if requested
        flag = prefs.get("graph_time_stamp", True)
        if flag:
            timeString = "Generated on " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S ") + "UTC"
            time_size = prefs["text_size"] * 0.8
            figure.text(
                0.995, 0.005, timeString, ha="right", va="bottom", size=pixelToPoint(time_size, dpi), fontstyle="italic"
            )

        #########################################
        # Make the graph Legend if requested

        legend_flag = prefs["legend"]
        legend_ax = None
        column_width = legend.column_width
        if legend_flag:
            legend_position = prefs["legend_position"]
            # legend_width = float(prefs['legend_width'])
            # legend_height = float(prefs['legend_height'])
            legend_width, legend_height, legend_max_height = legend.getLegendSize()
            legend_padding = float(prefs["legend_padding"])
            if legend_position in ["right", "left"]:
                # One column in case of vertical legend
                legend_width = column_width + legend_padding
                legend_height = min(graph_height, legend_max_height)
                bottom = (height - title_size - title_padding - legend_height) / 2.0 / height
                if legend_position == "right":
                    left = 1.0 - (figure_padding + legend_width) / width
                else:
                    left = figure_padding / width
                    graph_left = graph_left + legend_width
                graph_width = graph_width - legend_width - legend_padding
            elif legend_position == "bottom":
                bottom = figure_padding / height
                left = (width - legend_width) / 2.0 / width
                graph_height = graph_height - legend_height - legend_padding
                graph_bottom = graph_bottom + legend_height + legend_padding

            legend_rect = (left, bottom, legend_width / width, legend_height / height)
            legend_ax = figure.add_axes(legend_rect)

        ###########################################
        # Make the plot spots
        plot_grid = prefs["plot_grid"]
        nx = int(plot_grid.split(":")[0])
        ny = int(plot_grid.split(":")[1])

        plot_axes = []
        for j in range(ny - 1, -1, -1):
            for i in range(nx):
                plot_rect = (
                    (graph_left + graph_width * i / nx) / width,
                    (graph_bottom + graph_height * j / ny) / height,
                    graph_width / nx / width,
                    graph_height / ny / height,
                )

                plot_axes.append(figure.add_axes(plot_rect))

        return legend_ax, plot_axes
Exemplo n.º 9
0
    def draw(self):

        PlotBase.draw(self)
        self.x_formatter_cb(self.ax)

        if self.gdata.isEmpty():
            return None

        tmp_x = []
        tmp_y = []

        # Evaluate the bar width
        width = float(self.width)
        if self.gdata.key_type == 'time':
            #width = (1 - self.bar_graph_space) * width / 86400.0
            width = width / 86400.0
            offset = 0
        elif self.gdata.key_type == 'string':
            self.bar_graph_space = 0.1
            width = (1 - self.bar_graph_space) * width
            offset = self.bar_graph_space / 2.0
        else:
            offset = 0

        start_plot = 0
        end_plot = 0
        if "starttime" in self.prefs and "endtime" in self.prefs:
            start_plot = date2num(
                datetime.datetime.fromtimestamp(
                    to_timestamp(self.prefs['starttime'])))
            end_plot = date2num(
                datetime.datetime.fromtimestamp(
                    to_timestamp(self.prefs['endtime'])))

        nKeys = self.gdata.getNumberOfKeys()
        tmp_b = []
        if self.prefs.has_key('log_yaxis'):
            tmp_b = [0.001] * nKeys
            ymin = 0.001
        else:
            tmp_b = [0.] * nKeys
            ymin = 0.

        self.polygons = []
        self.lines = []
        labels = self.gdata.getLabels()
        labels.reverse()

        # If it is a simple plot, no labels are used
        # Evaluate the most appropriate color in this case
        if self.gdata.isSimplePlot():
            labels = [('SimplePlot', 0.)]
            color = self.prefs.get('plot_color', 'Default')
            if color.find('#') != -1:
                self.palette.setColor('SimplePlot', color)
            else:
                labels = [(color, 0.)]

        seq_b = [(self.gdata.max_num_key + width, 0.0),
                 (self.gdata.min_num_key, 0.0)]
        zorder = 0.0
        dpi = self.prefs.get('dpi', 100)
        for label, num in labels:
            color = self.palette.getColor(label)
            ind = 0
            tmp_x = []
            tmp_y = []
            tmp_t = []
            plot_data = self.gdata.getPlotNumData(label)
            for key, value, error in plot_data:
                if value is None:
                    value = 0.

                tmp_x.append(offset + key)
                #tmp_y.append( ymin )
                tmp_y.append(0.001)
                tmp_x.append(offset + key)
                tmp_y.append(float(value) + tmp_b[ind])
                tmp_x.append(offset + key + width)
                tmp_y.append(float(value) + tmp_b[ind])
                tmp_x.append(offset + key + width)
                #tmp_y.append( ymin )
                tmp_y.append(0.001)
                tmp_t.append(float(value) + tmp_b[ind])
                ind += 1
            seq_t = zip(tmp_x, tmp_y)
            seq = seq_t + seq_b
            poly = Polygon(seq,
                           facecolor=color,
                           fill=True,
                           linewidth=pixelToPoint(0.2, dpi),
                           zorder=zorder)
            self.ax.add_patch(poly)
            self.polygons.append(poly)
            tmp_b = list(tmp_t)
            zorder -= 0.1

        tight_bars_flag = self.prefs.get('tight_bars', False)
        if tight_bars_flag:
            setp(self.polygons, linewidth=0.)

        #pivots = keys
        #for idx in range(len(pivots)):
        #    self.coords[ pivots[idx] ] = self.bars[idx]

        ymax = max(tmp_b)
        ymax *= 1.1

        if self.prefs.has_key('log_yaxis'):
            ymin = 0.001
        else:
            ymin = min(tmp_b, 0.)
            ymin *= 1.1

        xmax = max(tmp_x)
        if self.log_xaxis:
            xmin = 0.001
        else:
            xmin = 0

        ymin = self.prefs.get('ymin', ymin)
        ymax = self.prefs.get('ymax', ymax)
        xmin = self.prefs.get('xmin', xmin)
        xmax = self.prefs.get('xmax', xmax)

        self.ax.set_xlim(xmin=xmin, xmax=xmax + offset)
        self.ax.set_ylim(ymin=ymin, ymax=ymax)
        if self.gdata.key_type == 'time':
            if start_plot and end_plot:
                self.ax.set_xlim(xmin=start_plot, xmax=end_plot)
            else:
                self.ax.set_xlim(xmin=min(tmp_x), xmax=max(tmp_x))
Exemplo n.º 10
0
    def draw(self):

        prefs = self.prefs
        dpi = self.ax_contain.figure.get_dpi()

        # Update palette
        palette = prefs.get('colors', {})
        if palette:
            self.palette.addPalette(palette)

        xlabel = prefs.get('xlabel', '')
        ylabel = prefs.get('ylabel', '')
        xticks_flag = prefs.get('xticks', True)
        yticks_flag = prefs.get('yticks', True)

        text_size = prefs['text_size']
        text_padding = prefs['text_padding']

        label_text_size = prefs.get('label_text_size', text_size)
        label_text_size_point = pixelToPoint(label_text_size, dpi)
        tick_text_size = prefs.get('tick_text_size', text_size)
        tick_text_size_point = pixelToPoint(tick_text_size, dpi)

        ytick_length = prefs.get('ytick_length', 7 * tick_text_size)

        plot_title = prefs.get('plot_title', '')
        if not plot_title or plot_title == 'NoTitle':
            plot_title_size = 0
            plot_title_padding = 0
        else:
            plot_title_size = prefs.get('plot_title_size', text_size)
            plot_title_padding = prefs.get('plot_text_padding', text_padding)
        plot_title_size_point = pixelToPoint(plot_title_size, dpi)

        stats_flag = prefs.get('statistics_line', False)
        stats_line = ''
        stats_line_space = 0.
        if stats_flag:
            stats_line = self.gdata.getStatString()
            stats_line_size = label_text_size
            stats_line_padding = label_text_size * 2.
            stats_line_space = stats_line_size + stats_line_padding

        plot_padding = prefs['plot_padding']
        plot_left_padding = prefs.get('plot_left_padding', plot_padding)
        plot_right_padding = prefs.get('plot_right_padding', 0)
        plot_bottom_padding = prefs.get('plot_bottom_padding', plot_padding)
        plot_top_padding = prefs.get('plot_top_padding', 0)
        frame_flag = prefs['frame']

        # Create plot axes, and set properties
        left, bottom, width, height = self.ax_contain.get_window_extent(
        ).bounds
        l, b, f_width, f_height = self.figure.get_window_extent().bounds

        # Space needed for labels and ticks
        x_label_space = 0
        if xticks_flag:
            x_label_space += tick_text_size * 1.5
        if xlabel:
            x_label_space += label_text_size * 1.5
        y_label_space = 0
        if yticks_flag:
            y_label_space += ytick_length
        if ylabel:
            y_label_space += label_text_size * 1.5

        ax_plot_rect = ( float( plot_left_padding + left + y_label_space ) / f_width,
                         float( plot_bottom_padding + bottom + x_label_space + stats_line_space ) / f_height,
                         float( width - plot_left_padding - plot_right_padding - y_label_space ) / f_width,
                         float( height - plot_bottom_padding - plot_top_padding - x_label_space - \
                                plot_title_size - 2 * plot_title_padding - stats_line_space ) / f_height )
        ax = Axes(self.figure, ax_plot_rect)
        if prefs['square_axis']:
            l, b, a_width, a_height = ax.get_window_extent().bounds
            delta = abs(a_height - a_width)
            if a_height > a_width:
                a_height = a_width
                ax_plot_rect = (
                    float(plot_left_padding + left) / f_width,
                    float(plot_bottom_padding + bottom + delta / 2.) /
                    f_height,
                    float(width - plot_left_padding - plot_right_padding) /
                    f_width,
                    float(height - plot_bottom_padding - plot_title_size -
                          2 * plot_title_padding - delta) / f_height)
            else:
                a_width = a_height
                ax_plot_rect = (
                    float(plot_left_padding + left + delta / 2.) / f_width,
                    float(plot_bottom_padding + bottom) / f_height,
                    float(width - plot_left_padding - delta) / f_width,
                    float(height - plot_bottom_padding - plot_title_size -
                          2 * plot_title_padding) / f_height)
            ax.set_position(ax_plot_rect)

        self.figure.add_axes(ax)
        self.ax = ax
        frame = ax.patch
        frame.set_fill(False)

        if frame_flag.lower() == 'off':
            self.ax.set_axis_off()
            self.log_xaxis = False
            self.log_yaxis = False
        else:
            # If requested, make x/y axis logarithmic
            if prefs.get('log_xaxis', 'False').find('r') >= 0:
                ax.semilogx()
                self.log_xaxis = True
            else:
                self.log_xaxis = False
            if prefs.get('log_yaxis', 'False').find('r') >= 0:
                ax.semilogy()
                self.log_yaxis = True
            else:
                self.log_yaxis = False

            if xticks_flag:
                setp(ax.get_xticklabels(), family=prefs['font_family'])
                setp(ax.get_xticklabels(), fontname=prefs['font'])
                setp(ax.get_xticklabels(), size=tick_text_size_point)
            else:
                setp(ax.get_xticklabels(), size=0)

            if yticks_flag:
                setp(ax.get_yticklabels(), family=prefs['font_family'])
                setp(ax.get_yticklabels(), fontname=prefs['font'])
                setp(ax.get_yticklabels(), size=tick_text_size_point)
            else:
                setp(ax.get_yticklabels(), size=0)

            setp(ax.get_xticklines(), markeredgewidth=pixelToPoint(0.5, dpi))
            setp(ax.get_xticklines(),
                 markersize=pixelToPoint(text_size / 2., dpi))
            setp(ax.get_yticklines(), markeredgewidth=pixelToPoint(0.5, dpi))
            setp(ax.get_yticklines(),
                 markersize=pixelToPoint(text_size / 2., dpi))
            setp(ax.get_xticklines(), zorder=4.0)

            line_width = prefs.get('line_width', 1.0)
            frame_line_width = prefs.get('frame_line_width', line_width)
            grid_line_width = prefs.get('grid_line_width', 0.1)
            plot_line_width = prefs.get('plot_line_width', 0.1)

            setp(ax.patch, linewidth=pixelToPoint(plot_line_width, dpi))
            #setp( ax.spines, linewidth=pixelToPoint(frame_line_width,dpi) )
            #setp( ax.axvline(), linewidth=pixelToPoint(1.0,dpi) )
            axis_grid_flag = prefs.get('plot_axis_grid', True)
            if axis_grid_flag:
                ax.grid(True,
                        color='#555555',
                        linewidth=pixelToPoint(grid_line_width, dpi))

            plot_axis_flag = prefs.get('plot_axis', True)
            if plot_axis_flag:
                # Set labels
                if xlabel:
                    t = ax.set_xlabel(xlabel)
                    t.set_family(prefs['font_family'])
                    t.set_fontname(prefs['font'])
                    t.set_size(label_text_size)

                if ylabel:
                    t = ax.set_ylabel(ylabel)
                    t.set_family(prefs['font_family'])
                    t.set_fontname(prefs['font'])
                    t.set_size(label_text_size)
            else:
                self.ax.set_axis_off()

        # Create a plot title, if necessary
        if plot_title:
            self.ax.title = self.ax.text(
                0.5,
                1. + float(plot_title_padding) / height,
                plot_title,
                verticalalignment='bottom',
                horizontalalignment='center',
                size=pixelToPoint(plot_title_size, dpi),
                family=prefs['font_family'],
                fontname=prefs['font'])
            self.ax.title.set_transform(self.ax.transAxes)
            self.ax.title.set_family(prefs['font_family'])
            self.ax.title.set_fontname(prefs['font'])
        if stats_line:
            self.ax.stats = self.ax.text(0.5, (-stats_line_space) / height,
                                         stats_line,
                                         verticalalignment='top',
                                         horizontalalignment='center',
                                         size=pixelToPoint(
                                             stats_line_size, dpi))

            self.ax.stats.set_transform(self.ax.transAxes)
Exemplo n.º 11
0
  def draw( self ):

    prefs = self.prefs
    dpi = self.ax_contain.figure.get_dpi()

    # Update palette
    palette = prefs.get( 'colors', {} )
    if palette:
      self.palette.addPalette( palette )


    xlabel = prefs.get( 'xlabel', '' )
    ylabel = prefs.get( 'ylabel', '' )
    xticks_flag = prefs.get( 'xticks', True )
    yticks_flag = prefs.get( 'yticks', True )

    text_size = prefs['text_size']
    text_padding = prefs['text_padding']

    label_text_size = prefs.get( 'label_text_size', text_size )
    label_text_size_point = pixelToPoint( label_text_size, dpi )
    tick_text_size = prefs.get( 'tick_text_size', text_size )
    tick_text_size_point = pixelToPoint( tick_text_size, dpi )

    ytick_length = prefs.get( 'ytick_length', 7 * tick_text_size )

    plot_title = prefs.get( 'plot_title', '' )
    if not plot_title or plot_title == 'NoTitle':
      plot_title_size = 0
      plot_title_padding = 0
    else:
      plot_title_size = prefs.get( 'plot_title_size', text_size )
      plot_title_padding = prefs.get( 'plot_text_padding', text_padding )
    plot_title_size_point = pixelToPoint( plot_title_size, dpi )

    stats_flag = prefs.get( 'statistics_line', False )
    stats_line = ''
    stats_line_space = 0.
    if stats_flag:
      stats_line = self.gdata.getStatString()
      stats_line_size = label_text_size
      stats_line_padding = label_text_size * 2.
      stats_line_space = stats_line_size + stats_line_padding

    plot_padding = prefs['plot_padding']
    plot_left_padding = prefs.get( 'plot_left_padding', plot_padding )
    plot_right_padding = prefs.get( 'plot_right_padding', 0 )
    plot_bottom_padding = prefs.get( 'plot_bottom_padding', plot_padding )
    plot_top_padding = prefs.get( 'plot_top_padding', 0 )
    frame_flag = prefs['frame']

    # Create plot axes, and set properties
    left, bottom, width, height = self.ax_contain.get_window_extent().bounds
    l, b, f_width, f_height = self.figure.get_window_extent().bounds

    # Space needed for labels and ticks
    x_label_space = 0
    if xticks_flag:
      x_label_space += tick_text_size * 1.5
    if xlabel:
      x_label_space += label_text_size * 1.5
    y_label_space = 0
    if yticks_flag:
      y_label_space += ytick_length
    if ylabel:
      y_label_space += label_text_size * 1.5

    ax_plot_rect = ( float( plot_left_padding + left + y_label_space ) / f_width,
                     float( plot_bottom_padding + bottom + x_label_space + stats_line_space ) / f_height,
                     float( width - plot_left_padding - plot_right_padding - y_label_space ) / f_width,
                     float( height - plot_bottom_padding - plot_top_padding - x_label_space - \
                            plot_title_size - 2 * plot_title_padding - stats_line_space ) / f_height )
    ax = Axes( self.figure, ax_plot_rect )
    if prefs['square_axis']:
      l, b, a_width, a_height = ax.get_window_extent().bounds
      delta = abs( a_height - a_width )
      if a_height > a_width:
        a_height = a_width
        ax_plot_rect = ( float( plot_left_padding + left ) / f_width,
                         float( plot_bottom_padding + bottom + delta / 2. ) / f_height,
                         float( width - plot_left_padding - plot_right_padding ) / f_width,
                         float( height - plot_bottom_padding - plot_title_size - 2 * plot_title_padding - delta ) / f_height )
      else:
        a_width = a_height
        ax_plot_rect = ( float( plot_left_padding + left + delta / 2. ) / f_width,
                         float( plot_bottom_padding + bottom ) / f_height,
                         float( width - plot_left_padding - delta ) / f_width,
                         float( height - plot_bottom_padding - plot_title_size - 2 * plot_title_padding ) / f_height )
      ax.set_position( ax_plot_rect )


    self.figure.add_axes( ax )
    self.ax = ax
    frame = ax.patch
    frame.set_fill( False )

    if frame_flag.lower() == 'off':
      self.ax.set_axis_off()
      self.log_xaxis = False
      self.log_yaxis = False
    else:
      # If requested, make x/y axis logarithmic
      if prefs.get( 'log_xaxis', 'False' ).find( 'r' ) >= 0:
        ax.semilogx()
        self.log_xaxis = True
      else:
        self.log_xaxis = False
      if prefs.get( 'log_yaxis', 'False' ).find( 'r' ) >= 0:
        ax.semilogy()
        self.log_yaxis = True
      else:
        self.log_yaxis = False

      if xticks_flag:
        setp( ax.get_xticklabels(), family = prefs['font_family'] )
        setp( ax.get_xticklabels(), fontname = prefs['font'] )
        setp( ax.get_xticklabels(), size = tick_text_size_point )
      else:
        setp( ax.get_xticklabels(), size = 0 )

      if yticks_flag:
        setp( ax.get_yticklabels(), family = prefs['font_family'] )
        setp( ax.get_yticklabels(), fontname = prefs['font'] )
        setp( ax.get_yticklabels(), size = tick_text_size_point )
      else:
        setp( ax.get_yticklabels(), size = 0 )

      setp( ax.get_xticklines(), markeredgewidth = pixelToPoint( 0.5, dpi ) )
      setp( ax.get_xticklines(), markersize = pixelToPoint( text_size / 2., dpi ) )
      setp( ax.get_yticklines(), markeredgewidth = pixelToPoint( 0.5, dpi ) )
      setp( ax.get_yticklines(), markersize = pixelToPoint( text_size / 2., dpi ) )
      setp( ax.get_xticklines(), zorder = 4.0 )

      line_width = prefs.get( 'line_width', 1.0 )
      frame_line_width = prefs.get( 'frame_line_width', line_width )
      grid_line_width = prefs.get( 'grid_line_width', 0.1 )
      plot_line_width = prefs.get( 'plot_line_width', 0.1 )

      setp( ax.patch, linewidth = pixelToPoint( plot_line_width, dpi ) )
      #setp( ax.spines, linewidth=pixelToPoint(frame_line_width,dpi) )
      #setp( ax.axvline(), linewidth=pixelToPoint(1.0,dpi) )
      axis_grid_flag = prefs.get( 'plot_axis_grid', True )
      if axis_grid_flag:
        ax.grid( True, color = '#555555', linewidth = pixelToPoint( grid_line_width, dpi ) )

      plot_axis_flag = prefs.get( 'plot_axis', True )
      if plot_axis_flag:
      # Set labels
        if xlabel:
          t = ax.set_xlabel( xlabel )
          t.set_family( prefs['font_family'] )
          t.set_fontname( prefs['font'] )
          t.set_size( label_text_size )

        if ylabel:
          t = ax.set_ylabel( ylabel )
          t.set_family( prefs['font_family'] )
          t.set_fontname( prefs['font'] )
          t.set_size( label_text_size )
      else:
        self.ax.set_axis_off()


    # Create a plot title, if necessary
    if plot_title:
      self.ax.title = self.ax.text( 0.5,
                                    1. + float( plot_title_padding ) / height,
                                    plot_title,
                                    verticalalignment = 'bottom',
                                    horizontalalignment = 'center',
                                    size = pixelToPoint( plot_title_size, dpi ),
                                    family = prefs['font_family'],
                                    fontname = prefs['font'])
      self.ax.title.set_transform( self.ax.transAxes )
      self.ax.title.set_family( prefs['font_family'] )
      self.ax.title.set_fontname( prefs['font'] )
    if stats_line:
      self.ax.stats = self.ax.text( 0.5, ( -stats_line_space ) / height,
                                    stats_line,
                                    verticalalignment = 'top',
                                    horizontalalignment = 'center',
                                    size = pixelToPoint( stats_line_size, dpi ) )

      self.ax.stats.set_transform( self.ax.transAxes )
Exemplo n.º 12
0
    def draw(self):

        prefs = self.prefs
        dpi = self.ax_contain.figure.get_dpi()

        # Update palette
        palette = prefs.get("colors", {})
        if palette:
            self.palette.addPalette(palette)

        xlabel = prefs.get("xlabel", "")
        ylabel = prefs.get("ylabel", "")
        xticks_flag = prefs.get("xticks", True)
        yticks_flag = prefs.get("yticks", True)

        text_size = prefs["text_size"]
        text_padding = prefs["text_padding"]

        label_text_size = prefs.get("label_text_size", text_size)
        label_text_size_point = pixelToPoint(label_text_size, dpi)
        tick_text_size = prefs.get("tick_text_size", text_size)
        tick_text_size_point = pixelToPoint(tick_text_size, dpi)

        ytick_length = prefs.get("ytick_length", 7 * tick_text_size)

        plot_title = prefs.get("plot_title", "")
        if not plot_title or plot_title == "NoTitle":
            plot_title_size = 0
            plot_title_padding = 0
        else:
            plot_title_size = prefs.get("plot_title_size", text_size)
            plot_title_padding = prefs.get("plot_text_padding", text_padding)
        plot_title_size_point = pixelToPoint(plot_title_size, dpi)

        stats_flag = prefs.get("statistics_line", False)
        stats_line = ""
        stats_line_space = 0.0
        if stats_flag:
            stats_line = self.gdata.getStatString()
            stats_line_size = label_text_size
            stats_line_padding = label_text_size * 2.0
            stats_line_space = stats_line_size + stats_line_padding

        plot_padding = prefs["plot_padding"]
        plot_left_padding = prefs.get("plot_left_padding", plot_padding)
        plot_right_padding = prefs.get("plot_right_padding", 0)
        plot_bottom_padding = prefs.get("plot_bottom_padding", plot_padding)
        plot_top_padding = prefs.get("plot_top_padding", 0)
        frame_flag = prefs["frame"]

        # Create plot axes, and set properties
        left, bottom, width, height = self.ax_contain.get_window_extent(
        ).bounds
        l, b, f_width, f_height = self.figure.get_window_extent().bounds

        # Space needed for labels and ticks
        x_label_space = 0
        if xticks_flag:
            x_label_space += tick_text_size * 1.5
        if xlabel:
            x_label_space += label_text_size * 1.5
        y_label_space = 0
        if yticks_flag:
            y_label_space += ytick_length
        if ylabel:
            y_label_space += label_text_size * 1.5

        ax_plot_rect = (
            float(plot_left_padding + left + y_label_space) / f_width,
            float(plot_bottom_padding + bottom + x_label_space +
                  stats_line_space) / f_height,
            float(width - plot_left_padding - plot_right_padding -
                  y_label_space) / f_width,
            float(height - plot_bottom_padding - plot_top_padding -
                  x_label_space - plot_title_size - 2 * plot_title_padding -
                  stats_line_space) / f_height,
        )
        ax = Axes(self.figure, ax_plot_rect)
        if prefs["square_axis"]:
            l, b, a_width, a_height = ax.get_window_extent().bounds
            delta = abs(a_height - a_width)
            if a_height > a_width:
                a_height = a_width
                ax_plot_rect = (
                    float(plot_left_padding + left) / f_width,
                    float(plot_bottom_padding + bottom + delta / 2.0) /
                    f_height,
                    float(width - plot_left_padding - plot_right_padding) /
                    f_width,
                    float(height - plot_bottom_padding - plot_title_size -
                          2 * plot_title_padding - delta) / f_height,
                )
            else:
                a_width = a_height
                ax_plot_rect = (
                    float(plot_left_padding + left + delta / 2.0) / f_width,
                    float(plot_bottom_padding + bottom) / f_height,
                    float(width - plot_left_padding - delta) / f_width,
                    float(height - plot_bottom_padding - plot_title_size -
                          2 * plot_title_padding) / f_height,
                )
            ax.set_position(ax_plot_rect)

        self.figure.add_axes(ax)
        self.ax = ax
        frame = ax.patch
        frame.set_fill(False)

        if frame_flag.lower() == "off":
            self.ax.set_axis_off()
            self.log_xaxis = False
            self.log_yaxis = False
        else:
            # If requested, make x/y axis logarithmic
            if prefs.get("log_xaxis", "False").find("r") >= 0:
                ax.semilogx()
                self.log_xaxis = True
            else:
                self.log_xaxis = False
            if prefs.get("log_yaxis", "False").find("r") >= 0:
                ax.semilogy()
                self.log_yaxis = True
            else:
                self.log_yaxis = False

            if xticks_flag:
                setp(ax.get_xticklabels(), family=prefs["font_family"])
                setp(ax.get_xticklabels(), fontname=prefs["font"])
                setp(ax.get_xticklabels(), size=tick_text_size_point)
            else:
                setp(ax.get_xticklabels(), size=0)

            if yticks_flag:
                setp(ax.get_yticklabels(), family=prefs["font_family"])
                setp(ax.get_yticklabels(), fontname=prefs["font"])
                setp(ax.get_yticklabels(), size=tick_text_size_point)
            else:
                setp(ax.get_yticklabels(), size=0)

            setp(ax.get_xticklines(), markeredgewidth=pixelToPoint(0.5, dpi))
            setp(ax.get_xticklines(),
                 markersize=pixelToPoint(text_size / 2.0, dpi))
            setp(ax.get_yticklines(), markeredgewidth=pixelToPoint(0.5, dpi))
            setp(ax.get_yticklines(),
                 markersize=pixelToPoint(text_size / 2.0, dpi))
            setp(ax.get_xticklines(), zorder=4.0)

            line_width = prefs.get("line_width", 1.0)
            frame_line_width = prefs.get("frame_line_width", line_width)
            grid_line_width = prefs.get("grid_line_width", 0.1)
            plot_line_width = prefs.get("plot_line_width", 0.1)

            setp(ax.patch, linewidth=pixelToPoint(plot_line_width, dpi))
            # setp( ax.spines, linewidth=pixelToPoint(frame_line_width,dpi) )
            # setp( ax.axvline(), linewidth=pixelToPoint(1.0,dpi) )
            axis_grid_flag = prefs.get("plot_axis_grid", True)
            if axis_grid_flag:
                ax.grid(True,
                        color="#555555",
                        linewidth=pixelToPoint(grid_line_width, dpi))

            plot_axis_flag = prefs.get("plot_axis", True)
            if plot_axis_flag:
                # Set labels
                if xlabel:
                    t = ax.set_xlabel(xlabel)
                    t.set_fontname(prefs["font"])
                    t.set_fontsize(label_text_size)

                if ylabel:
                    t = ax.set_ylabel(ylabel)
                    t.set_fontname(prefs["font"])
                    t.set_fontsize(label_text_size)
            else:
                self.ax.set_axis_off()

        # Create a plot title, if necessary
        if plot_title:
            self.ax.title = self.ax.text(
                0.5,
                1.0 + float(plot_title_padding) / height,
                plot_title,
                verticalalignment="bottom",
                horizontalalignment="center",
                size=pixelToPoint(plot_title_size, dpi),
                family=prefs["font_family"],
                fontname=prefs["font"],
            )
            self.ax.title.set_transform(self.ax.transAxes)
            self.ax.title.set_fontname(prefs["font"])
        if stats_line:
            self.ax.stats = self.ax.text(
                0.5,
                (-stats_line_space) / height,
                stats_line,
                verticalalignment="top",
                horizontalalignment="center",
                size=pixelToPoint(stats_line_size, dpi),
            )

            self.ax.stats.set_transform(self.ax.transAxes)
Exemplo n.º 13
0
  def draw( self ):

    PlotBase.draw(self)
    self.x_formatter_cb(self.ax)

    if self.gdata.isEmpty():
      return None

    tmp_x = []; tmp_y = []

    # Evaluate the bar width
    width = float(self.width)
    if self.gdata.key_type == 'time':
      #width = (1 - self.bar_graph_space) * width / 86400.0
      width = width / 86400.0
      offset = 0
    elif self.gdata.key_type == 'string':
      self.bar_graph_space = 0.1
      width = (1 - self.bar_graph_space) * width
      offset = self.bar_graph_space / 2.0
    else:
      offset = 0

    start_plot = 0
    end_plot = 0
    if "starttime" in self.prefs and "endtime" in self.prefs:
      start_plot = date2num( datetime.datetime.fromtimestamp(to_timestamp(self.prefs['starttime'])))
      end_plot = date2num( datetime.datetime.fromtimestamp(to_timestamp(self.prefs['endtime'])))

    nKeys = self.gdata.getNumberOfKeys()
    tmp_b = []
    if self.prefs.has_key('log_yaxis'):
      tmp_b = [0.001]*nKeys
      ymin = 0.001
    else:
      tmp_b = [0.]*nKeys
      ymin = 0.

    self.polygons = []
    self.lines = []
    labels = self.gdata.getLabels()
    labels.reverse()

    # If it is a simple plot, no labels are used
    # Evaluate the most appropriate color in this case
    if self.gdata.isSimplePlot():
      labels = [('SimplePlot',0.)]
      color = self.prefs.get('plot_color','Default')
      if color.find('#') != -1:
        self.palette.setColor('SimplePlot',color)
      else:
        labels = [(color,0.)]

    seq_b = [(self.gdata.max_num_key+width,0.0),(self.gdata.min_num_key,0.0)]
    zorder = 0.0
    dpi = self.prefs.get('dpi',100)
    for label,num in labels:
      color = self.palette.getColor(label)
      ind = 0
      tmp_x = []
      tmp_y = []
      tmp_t = []
      plot_data = self.gdata.getPlotNumData(label)
      for key, value, error in plot_data:
        if value is None:
          value = 0.

        tmp_x.append( offset+key )
        #tmp_y.append( ymin )
        tmp_y.append( 0.001 )
        tmp_x.append( offset+key )
        tmp_y.append( float(value)+tmp_b[ind] )
        tmp_x.append( offset+key+width )
        tmp_y.append( float(value)+tmp_b[ind] )
        tmp_x.append( offset+key+width )
        #tmp_y.append( ymin )
        tmp_y.append( 0.001 )
        tmp_t.append(float(value)+tmp_b[ind])
        ind += 1
      seq_t = zip(tmp_x,tmp_y)
      seq = seq_t+seq_b
      poly = Polygon( seq, facecolor=color, fill=True,
                      linewidth=pixelToPoint(0.2,dpi),
                      zorder=zorder)
      self.ax.add_patch( poly )
      self.polygons.append( poly )
      tmp_b = list(tmp_t)
      zorder -= 0.1

    tight_bars_flag = self.prefs.get('tight_bars',False)
    if tight_bars_flag:
      setp( self.polygons, linewidth=0. )

    #pivots = keys
    #for idx in range(len(pivots)):
    #    self.coords[ pivots[idx] ] = self.bars[idx]

    ymax = max(tmp_b)
    ymax *= 1.1

    if self.prefs.has_key('log_yaxis'):
      ymin = 0.001
    else:
      ymin = min( tmp_b, 0. )
      ymin *= 1.1

    xmax=max(tmp_x)
    if self.log_xaxis:
      xmin = 0.001
    else:
      xmin = 0

    ymin = self.prefs.get( 'ymin', ymin )
    ymax = self.prefs.get( 'ymax', ymax )
    xmin = self.prefs.get( 'xmin', xmin )
    xmax = self.prefs.get( 'xmax', xmax )

    self.ax.set_xlim( xmin=xmin, xmax=xmax+offset )
    self.ax.set_ylim( ymin=ymin, ymax=ymax )
    if self.gdata.key_type == 'time':
      if start_plot and end_plot:
        self.ax.set_xlim( xmin=start_plot, xmax=end_plot)
      else:
        self.ax.set_xlim( xmin=min(tmp_x), xmax=max(tmp_x))
Exemplo n.º 14
0
    def layoutFigure(self, legend):

        prefs = self.prefs

        # Get the main Figure object
        # self.figure = Figure()
        figure = self.figure
        self.canvas = FigureCanvasAgg(figure)

        dpi = prefs["dpi"]
        width = float(prefs["width"])
        height = float(prefs["height"])
        width_inch = width / dpi
        height_inch = height / dpi
        figure.set_size_inches(width_inch, height_inch)
        figure.set_dpi(dpi)
        figure.set_facecolor(prefs.get("background_color", "white"))

        figure_padding = float(prefs["figure_padding"])
        figure_left_padding = float(
            prefs.get("figure_left_padding", figure_padding))
        figure_right_padding = float(
            prefs.get("figure_right_padding", figure_padding))
        figure_top_padding = float(
            prefs.get("figure_top_padding", figure_padding))
        figure_bottom_padding = float(
            prefs.get("figure_bottom_padding", figure_padding))

        text_size = prefs.get("text_size", 8)
        text_padding = prefs.get("text_padding", 5)

        #######################################
        # Make the graph title

        title = prefs.get("title", "")
        subtitle = ""
        title_size = 0
        title_padding = 0
        if title:
            title_size = prefs.get("title_size", 1.5 * text_size)
            title_padding = float(
                prefs.get("title_padding", 1.5 * text_padding))
            figure.text(
                0.5,
                1.0 - (title_size + figure_padding) / height,
                title,
                ha="center",
                va="bottom",
                size=pixelToPoint(title_size, dpi),
            )

            subtitle = prefs.get("subtitle", "")
            if subtitle:
                sublines = subtitle.split("\n")
                nsublines = len(sublines)
                subtitle_size = prefs.get("subtitle_size", 1.2 * text_size)
                subtitle_padding = float(
                    prefs.get("subtitle_padding", 1.2 * text_padding))
                top_offset = subtitle_size + subtitle_padding + title_size + figure_padding
                for subline in sublines:
                    figure.text(
                        0.5,
                        1.0 - (top_offset) / height,
                        subline,
                        ha="center",
                        va="bottom",
                        size=pixelToPoint(subtitle_size, dpi),
                        fontstyle="italic",
                    )
                    top_offset += subtitle_size + subtitle_padding

        ########################################
        # Evaluate the plot area dimensions
        graph_width = width - figure_left_padding - figure_right_padding
        graph_height = height - figure_top_padding - figure_bottom_padding
        if title:
            graph_height = graph_height - title_padding - title_size
        if subtitle:
            graph_height = graph_height - nsublines * (subtitle_size +
                                                       subtitle_padding)
        graph_left = figure_left_padding
        graph_bottom = figure_bottom_padding

        #########################################
        # Make the plot time stamp if requested
        flag = prefs.get("graph_time_stamp", True)
        if flag:
            timeString = "Generated on " + datetime.datetime.utcnow().strftime(
                "%Y-%m-%d %H:%M:%S ") + "UTC"
            time_size = prefs["text_size"] * 0.8
            figure.text(0.995,
                        0.005,
                        timeString,
                        ha="right",
                        va="bottom",
                        size=pixelToPoint(time_size, dpi),
                        fontstyle="italic")

        #########################################
        # Make the graph Legend if requested

        legend_flag = prefs["legend"]
        legend_ax = None
        column_width = legend.column_width
        if legend_flag:
            legend_position = prefs["legend_position"]
            # legend_width = float(prefs['legend_width'])
            # legend_height = float(prefs['legend_height'])
            legend_width, legend_height, legend_max_height = legend.getLegendSize(
            )
            legend_padding = float(prefs["legend_padding"])
            if legend_position in ["right", "left"]:
                # One column in case of vertical legend
                legend_width = column_width + legend_padding
                legend_height = min(graph_height, legend_max_height)
                bottom = (height - title_size - title_padding -
                          legend_height) / 2.0 / height
                if legend_position == "right":
                    left = 1.0 - (figure_padding + legend_width) / width
                else:
                    left = figure_padding / width
                    graph_left = graph_left + legend_width
                graph_width = graph_width - legend_width - legend_padding
            elif legend_position == "bottom":
                bottom = figure_padding / height
                left = (width - legend_width) / 2.0 / width
                graph_height = graph_height - legend_height - legend_padding
                graph_bottom = graph_bottom + legend_height + legend_padding

            legend_rect = (left, bottom, legend_width / width,
                           legend_height / height)
            legend_ax = figure.add_axes(legend_rect)

        ###########################################
        # Make the plot spots
        plot_grid = prefs["plot_grid"]
        nx = int(plot_grid.split(":")[0])
        ny = int(plot_grid.split(":")[1])

        plot_axes = []
        for j in range(ny - 1, -1, -1):
            for i in range(nx):
                plot_rect = (
                    (graph_left + graph_width * i / nx) / width,
                    (graph_bottom + graph_height * j / ny) / height,
                    graph_width / nx / width,
                    graph_height / ny / height,
                )

                plot_axes.append(figure.add_axes(plot_rect))

        return legend_ax, plot_axes
Exemplo n.º 15
0
  def draw( self ):

    PlotBase.draw( self )
    self.x_formatter_cb( self.ax )

    if self.gdata.isEmpty():
      return None

    # Evaluate the bar width
    width = float( self.width )
    offset = 0.
    if self.gdata.key_type == 'time':
      width = width / 86400.0

    start_plot = 0
    end_plot = 0
    if "starttime" in self.prefs and "endtime" in self.prefs:
      start_plot = date2num( datetime.datetime.fromtimestamp( to_timestamp( self.prefs['starttime'] ) ) )
      end_plot = date2num( datetime.datetime.fromtimestamp( to_timestamp( self.prefs['endtime'] ) ) )

    labels = self.gdata.getLabels()
    nKeys = self.gdata.getNumberOfKeys()
    tmp_b = []
    tmp_x = []
    tmp_y = []

    self.bars = []
    labels = self.gdata.getLabels()
    nLabel = 0
    labelNames = []
    colors = []
    xmin = None
    xmax = None
    for label, _num in labels:
      labelNames.append( label )
      for key, value, _error in self.gdata.getPlotNumData( label ):

        if xmin is None or xmin > ( key + offset ):
          xmin = key + offset
        if xmax is None or xmax < ( key + offset ):
          xmax = key + offset

        if value is not None:
          colors.append( self.getQualityColor( value ) )
          tmp_x.append( key + offset )
          tmp_y.append( 1. )
          tmp_b.append( float( nLabel ) )

      nLabel += 1

    self.bars += self.ax.bar( tmp_x, tmp_y, bottom = tmp_b, width = width, color = colors )

    dpi = self.prefs.get( 'dpi', 100 )
    setp( self.bars, linewidth = pixelToPoint( 0.5, dpi ), edgecolor = '#AAAAAA' )

    #pivots = keys
    #for idx in range(len(pivots)):
    #    self.coords[ pivots[idx] ] = self.bars[idx]

    ymax = float( nLabel )
    self.ax.set_xlim( xmin = 0., xmax = xmax + width + offset )
    self.ax.set_ylim( ymin = 0., ymax = ymax )
    if self.gdata.key_type == 'time':
      if start_plot and end_plot:
        self.ax.set_xlim( xmin = start_plot, xmax = end_plot )
      else:
        self.ax.set_xlim( xmin = min( tmp_x ), xmax = max( tmp_x ) )
    self.ax.set_yticks( [ i + 0.5 for i in range( nLabel ) ] )
    self.ax.set_yticklabels( labelNames )
    setp( self.ax.get_xticklines(), markersize = 0. )
    setp( self.ax.get_yticklines(), markersize = 0. )

    cax, kw = make_axes( self.ax, orientation = 'vertical', fraction = 0.07 )
    cb = ColorbarBase( cax, cmap = self.cmap, norm = self.norms,
                       boundaries = self.cbBoundaries,
                       values = self.cbValues,
                       ticks = self.cbTicks )
    cb.draw_all()