Exemplo n.º 1
0
    def plot2axes(self,
                  axes,
                  edgecolor='black',
                  angle=0.0,
                  fill=False,
                  alpha=1,
                  facecolor='g'):
        """Plot the Rectangle to the axes.

        Parameters
        ----------
        axes : matplotlib.axes.Axes
            An MPL axes to plot to.
        edgecolor : str
            The color of the circle.
        angle : float
            Angle of the rectangle.
        fill : bool
            Whether to fill the rectangle with color or leave hollow.
        """
        axes.add_patch(
            mpl_Rectangle((self.bl_corner.x, self.bl_corner.y),
                          width=self.width,
                          height=self.height,
                          angle=angle,
                          edgecolor=edgecolor,
                          alpha=alpha,
                          facecolor=facecolor,
                          fill=fill))
Exemplo n.º 2
0
    def add_to_axes(self, axes, edgecolor="black", angle=0.0, fill=False, alpha=1, facecolor="g"):
        """Plot the Rectangle to the axes.

        Parameters
        ----------
        axes : matplotlib.axes.Axes
            An MPL axes to plot to.
        edgecolor : str
            The color of the circle.
        angle : float
            Angle of the rectangle.
        fill : bool
            Whether to fill the rectangle with color or leave hollow.
        """
        axes.add_patch(
            mpl_Rectangle(
                (self.bl_corner.x, self.bl_corner.y),
                width=self.width,
                height=self.height,
                angle=angle,
                edgecolor=edgecolor,
                alpha=alpha,
                facecolor=facecolor,
                fill=fill,
            )
        )
Exemplo n.º 3
0
    def to_mpl_patch(self):

        """
        This function ...
        :return:
        """

        return mpl_Rectangle((self.center.x, self.center.y), self.width, self.height, edgecolor='green', facecolor='none', lw=3, alpha=0.7)
Exemplo n.º 4
0
    def to_mpl_patch(self):
        """
        This function ...
        :return:
        """

        return mpl_Rectangle((self.center.x, self.center.y),
                             self.width,
                             self.height,
                             edgecolor='green',
                             facecolor='none',
                             lw=3,
                             alpha=0.7)
Exemplo n.º 5
0
    def _draw_rectangle(self, event):
        if not self.moving_flag \
                and not self.mouse_on_legend \
                and self.xypress is not None:

            x_start, y_start = self.xypress
            x_end, y_end = event.x, event.y

            if self.rect_bg is None:
                self.rect_bg = self.figure.canvas.copy_from_bbox(self.bbox)
            else:
                self.figure.canvas.restore_region(self.rect_bg)

            inv = self.transData.inverted()
            ax_x_start, ax_y_start = inv.transform((x_start, y_start))
            ax_x_end, ax_y_end = inv.transform((x_end, y_end))

            if self.xlock:
                ax_x_start = self.__convert_axes_to_data(0, 0)[0]
                ax_x_end = self.__convert_axes_to_data(1, 1)[0]

            if self.ylock:
                ax_y_start = self.__convert_axes_to_data(0, 0)[1]
                ax_y_end = self.__convert_axes_to_data(1, 1)[1]

            self.zoom_rect = (min(ax_x_start,
                                  ax_x_end), min(ax_y_start, ax_y_end),
                              max(ax_x_start,
                                  ax_x_end), max(ax_y_start, ax_y_end))

            rec = mpl_Rectangle((ax_x_start, ax_y_start),
                                width=(ax_x_end - ax_x_start),
                                height=(ax_y_end - ax_y_start),
                                fc="#0000ff",
                                ec="#000000",
                                alpha=0.1,
                                lw=1,
                                transform=self.transData,
                                figure=self.figure)

            self.draw_artist(rec)
            self.figure.canvas.blit(self.bbox)

            # draw ending cross
            select_bg = self.figure.canvas.copy_from_bbox(self.bbox)
            self._draw_cross(event, select_bg)
Exemplo n.º 6
0
    def _draw_rectangle(self, event):
        if not self.moving_flag \
                and not self.mouse_on_legend \
                and self.xypress is not None:

            x_start, y_start = self.xypress
            x_end, y_end = event.x, event.y

            if self.rect_bg is None:
                self.rect_bg = self.figure.canvas.copy_from_bbox(self.bbox)
            else:
                self.figure.canvas.restore_region(self.rect_bg)

            inv = self.transData.inverted()
            ax_x_start, ax_y_start = inv.transform((x_start, y_start))
            ax_x_end, ax_y_end = inv.transform((x_end, y_end))

            if self.xlock:
                ax_x_start = self.__convert_axes_to_data(0, 0)[0]
                ax_x_end = self.__convert_axes_to_data(1, 1)[0]

            if self.ylock:
                ax_y_start = self.__convert_axes_to_data(0, 0)[1]
                ax_y_end = self.__convert_axes_to_data(1, 1)[1]

            self.zoom_rect = (
                min(ax_x_start, ax_x_end),
                min(ax_y_start, ax_y_end),
                max(ax_x_start, ax_x_end),
                max(ax_y_start, ax_y_end))

            rec = mpl_Rectangle(
                (ax_x_start, ax_y_start),
                width=(ax_x_end - ax_x_start),
                height=(ax_y_end - ax_y_start),
                fc="#0000ff", ec="#000000", alpha=0.1, lw=1,
                transform=self.transData, figure=self.figure)

            self.draw_artist(rec)
            self.figure.canvas.blit(self.bbox)

            # draw ending cross
            select_bg = self.figure.canvas.copy_from_bbox(self.bbox)
            self._draw_cross(event, select_bg)
Exemplo n.º 7
0
def utilization_chart(names,
                      values,
                      title="",
                      xlabel="",
                      ylabel="",
                      idles=None):

    if not names or not values:
        return _empty_chart(title, xlabel, ylabel)

    figure = mpl_Figure()
    canvas = mpl_FigureCanvas(figure)
    figure.set_canvas(canvas)

    # TODO: Change it to TimeChart
    ax = figure.add_subplot(111, projection=BasicChart.name)

    ywidth = 2
    yticks = []

    if idles is not None:
        for i, lidle in enumerate(idles):
            y = ((i+1) * ywidth) + (i+1)
            ax.broken_barh(
                lidle, (y, ywidth),
                edgecolor='face', facecolor='#EAA769')

    for i, ldata in enumerate(values):
        y = (ywidth+1) * (i+ 1)
        yticks.append(y + ywidth/2)
        ax.broken_barh(
            ldata, (y, ywidth),
            edgecolor='face', facecolor='green')

    ax.set_yticks(yticks)
    ax.set_yticklabels(names)

    for label in ax.xaxis.get_ticklabels():
        label.set_rotation(-35)
        label.set_horizontalalignment('left')
    for i, label in enumerate(ax.yaxis.get_ticklabels()):
        # add 3 white space on the begining of name
        names[i] = "   %s" % names[i]
        label.set_horizontalalignment("left")
        label.set_verticalalignment('center')

    p = mpl_Rectangle((0, 0), 1, 1, edgecolor='green', fc='green', alpha=0.75)
    if idles is not None:
        idle_leg = mpl_Rectangle((0,0), 1, 1, edgecolor='#eaa769', fc='#eaa769', alpha=0.75)
        ax.plegend = ax.legend(
            [p,idle_leg], ["Running", "Idle"], loc="upper left", fancybox=True, shadow=True)
    else:
        ax.plegend = ax.legend(
            [p], ["Running"], loc="upper left", fancybox=True, shadow=True)

    ax.xaxis.grid(True, linestyle="-", which='major', color='black', alpha=0.7)
    ax.xaxis.set_major_formatter(mpl_FuncFormatter(
        lambda time, pos: utils.time_to_string(time)[:-7]))
    ax.set_xlim(xmin=0)
    ax.get_figure().tight_layout()

    ax.set_title(title)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)

    # resize figure
    w, h = figure.get_size_inches()
    figure.set_size_inches(w, len(values) * 0.4)
    return ChartWidget(figure, ylock=True)
Exemplo n.º 8
0
def utilization_chart(names,
                      values,
                      title="",
                      xlabel="",
                      ylabel="",
                      idles=None):

    if not names or not values:
        return _empty_chart(title, xlabel, ylabel)

    figure = mpl_Figure()
    canvas = mpl_FigureCanvas(figure)
    figure.set_canvas(canvas)

    # TODO: Change it to TimeChart
    ax = figure.add_subplot(111, projection=BasicChart.name)

    ywidth = 2
    yticks = []

    if idles is not None:
        for i, lidle in enumerate(idles):
            y = ((i + 1) * ywidth) + (i + 1)
            ax.broken_barh(lidle, (y, ywidth),
                           edgecolor='face',
                           facecolor='#EAA769')

    for i, ldata in enumerate(values):
        y = (ywidth + 1) * (i + 1)
        yticks.append(y + ywidth / 2)
        ax.broken_barh(ldata, (y, ywidth), edgecolor='face', facecolor='green')

    ax.set_yticks(yticks)
    ax.set_yticklabels(names)

    for label in ax.xaxis.get_ticklabels():
        label.set_rotation(-35)
        label.set_horizontalalignment('left')
    for i, label in enumerate(ax.yaxis.get_ticklabels()):
        # add 3 white space on the begining of name
        names[i] = "   %s" % names[i]
        label.set_horizontalalignment("left")
        label.set_verticalalignment('center')

    p = mpl_Rectangle((0, 0), 1, 1, edgecolor='green', fc='green', alpha=0.75)
    if idles is not None:
        idle_leg = mpl_Rectangle((0, 0),
                                 1,
                                 1,
                                 edgecolor='#eaa769',
                                 fc='#eaa769',
                                 alpha=0.75)
        ax.plegend = ax.legend([p, idle_leg], ["Running", "Idle"],
                               loc="upper left",
                               fancybox=True,
                               shadow=True)
    else:
        ax.plegend = ax.legend([p], ["Running"],
                               loc="upper left",
                               fancybox=True,
                               shadow=True)

    ax.xaxis.grid(True, linestyle="-", which='major', color='black', alpha=0.7)
    ax.xaxis.set_major_formatter(
        mpl_FuncFormatter(lambda time, pos: utils.time_to_string(time)[:-7]))
    ax.set_xlim(xmin=0)
    ax.get_figure().tight_layout()

    ax.set_title(title)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)

    # resize figure
    w, h = figure.get_size_inches()
    figure.set_size_inches(w, len(values) * 0.4)
    return ChartWidget(figure, ylock=True)