当前位置: 首页>>代码示例>>Python>>正文


Python offsetbox.TextArea类代码示例

本文整理汇总了Python中matplotlib.offsetbox.TextArea的典型用法代码示例。如果您正苦于以下问题:Python TextArea类的具体用法?Python TextArea怎么用?Python TextArea使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TextArea类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Legend


#.........这里部分代码省略.........
                          fontproperties=self.prop,
                          )

        labelboxes = []
        handleboxes = []


        # The approximate height and descent of text. These values are
        # only used for plotting the legend handle.
        descent = 0.35*self._approx_text_height()*(self.handleheight - 0.7)
        # 0.35 and 0.7 are just heuristic numbers. this may need to be improbed
        height = self._approx_text_height() * self.handleheight - descent
        # each handle needs to be drawn inside a box of (x, y, w, h) =
        # (0, -descent, width, height).  And their corrdinates should
        # be given in the display coordinates.

        # The transformation of each handle will be automatically set
        # to self.get_trasnform(). If the artist does not uses its
        # default trasnform (eg, Collections), you need to
        # manually set their transform to the self.get_transform().


        legend_handler_map = self.get_legend_handler_map()

        for orig_handle, lab in zip(handles, labels):

            handler = self.get_legend_handler(legend_handler_map, orig_handle)

            if handler is None:
                warnings.warn("Legend does not support %s\nUse proxy artist instead.\n\nhttp://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist\n" % (str(orig_handle),))
                handle_list.append(None)
                continue

            textbox = TextArea(lab, textprops=label_prop,
                               multilinebaseline=True, minimumdescent=True)
            text_list.append(textbox._text)

            labelboxes.append(textbox)

            handlebox = DrawingArea(width=self.handlelength*fontsize,
                                    height=height,
                                    xdescent=0., ydescent=descent)

            handle = handler(self, orig_handle, \
                             #xdescent, ydescent, width, height,
                             fontsize,
                             handlebox)
            handle_list.append(handle)




            handleboxes.append(handlebox)


        if len(handleboxes) > 0:

            # We calculate number of lows in each column. The first
            # (num_largecol) columns will have (nrows+1) rows, and remaing
            # (num_smallcol) columns will have (nrows) rows.
            ncol = min(self._ncol, len(handleboxes))
            nrows, num_largecol = divmod(len(handleboxes), ncol)
            num_smallcol = ncol-num_largecol

            # starting index of each column and number of rows in it.
            largecol = safezip(range(0, num_largecol*(nrows+1), (nrows+1)),
开发者ID:EnochManohar,项目名称:matplotlib,代码行数:67,代码来源:legend.py

示例2: do_plot

    def do_plot(self, wallet, history):
        balance_Val=[]
        fee_val=[]
        value_val=[]
        datenums=[]
        unknown_trans = 0
        pending_trans = 0
        counter_trans = 0
        balance = 0
        for item in history:
            tx_hash, confirmations, value, timestamp, balance = item
            if confirmations:
                if timestamp is not None:
                    try:
                        datenums.append(md.date2num(datetime.datetime.fromtimestamp(timestamp)))
                        balance_Val.append(1000.*balance/COIN)
                    except [RuntimeError, TypeError, NameError] as reason:
                        unknown_trans += 1
                        pass
                else:
                    unknown_trans += 1
            else:
                pending_trans += 1

            value_val.append(1000.*value/COIN)
            if tx_hash:
                label, is_default_label = wallet.get_label(tx_hash)
                label = label.encode('utf-8')
            else:
                label = ""


        f, axarr = plt.subplots(2, sharex=True)

        plt.subplots_adjust(bottom=0.2)
        plt.xticks( rotation=25 )
        ax=plt.gca()
        x=19
        test11="Unknown transactions =  "+str(unknown_trans)+" Pending transactions =  "+str(pending_trans)+" ."
        box1 = TextArea(" Test : Number of pending transactions", textprops=dict(color="k"))
        box1.set_text(test11)


        box = HPacker(children=[box1],
            align="center",
            pad=0.1, sep=15)

        anchored_box = AnchoredOffsetbox(loc=3,
            child=box, pad=0.5,
            frameon=True,
            bbox_to_anchor=(0.5, 1.02),
            bbox_transform=ax.transAxes,
            borderpad=0.5,
        )


        ax.add_artist(anchored_box)


        plt.ylabel('mBTC')
        plt.xlabel('Dates')
        xfmt = md.DateFormatter('%Y-%m-%d')
        ax.xaxis.set_major_formatter(xfmt)


        axarr[0].plot(datenums,balance_Val,marker='o',linestyle='-',color='blue',label='Balance')
        axarr[0].legend(loc='upper left')
        axarr[0].set_title('History Transactions')


        xfmt = md.DateFormatter('%Y-%m-%d')
        ax.xaxis.set_major_formatter(xfmt)
        axarr[1].plot(datenums,value_val,marker='o',linestyle='-',color='green',label='Value')


        axarr[1].legend(loc='upper left')
     #   plt.annotate('unknown transaction = %d \n pending transactions = %d' %(unknown_trans,pending_trans),xy=(0.7,0.05),xycoords='axes fraction',size=12)
        plt.show()
开发者ID:FuzzyHobbit,项目名称:electrum,代码行数:78,代码来源:plot.py

示例3: _init_legend_box

    def _init_legend_box(self, handles, labels):
        """
        Initiallize the legend_box. The legend_box is an instance of
        the OffsetBox, which is packed with legend handles and
        texts. Once packed, their location is calculated during the
        drawing time.
        """

        fontsize = self._fontsize

        # legend_box is a HPacker, horizontally packed with
        # columns. Each column is a VPacker, vertically packed with
        # legend items. Each legend item is HPacker packed with
        # legend handleBox and labelBox. handleBox is an instance of
        # offsetbox.DrawingArea which contains legend handle. labelBox
        # is an instance of offsetbox.TextArea which contains legend
        # text.


        text_list = []  # the list of text instances
        handle_list = []  # the list of text instances

        label_prop = dict(verticalalignment='baseline',
                          horizontalalignment='left',
                          fontproperties=self.prop,
                          )

        labelboxes = []
        handleboxes = []


        # The approximate height and descent of text. These values are
        # only used for plotting the legend handle.
        descent = 0.35*self._approx_text_height()*(self.handleheight - 0.7)
        # 0.35 and 0.7 are just heuristic numbers. this may need to be improbed
        height = self._approx_text_height() * self.handleheight - descent
        # each handle needs to be drawn inside a box of (x, y, w, h) =
        # (0, -descent, width, height).  And their corrdinates should
        # be given in the display coordinates.

        # The transformation of each handle will be automatically set
        # to self.get_trasnform(). If the artist does not uses its
        # default trasnform (eg, Collections), you need to
        # manually set their transform to the self.get_transform().


        legend_handler_map = self.get_legend_handler_map()

        for orig_handle, lab in zip(handles, labels):

            handler = self.get_legend_handler(legend_handler_map, orig_handle)

            if handler is None:
                warnings.warn("Legend does not support %s\nUse proxy artist instead.\n\nhttp://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist\n" % (str(orig_handle),))
                handle_list.append(None)
                continue

            textbox = TextArea(lab, textprops=label_prop,
                               multilinebaseline=True, minimumdescent=True)
            text_list.append(textbox._text)

            labelboxes.append(textbox)

            handlebox = DrawingArea(width=self.handlelength*fontsize,
                                    height=height,
                                    xdescent=0., ydescent=descent)

            handle = handler(self, orig_handle, \
                             #xdescent, ydescent, width, height,
                             fontsize,
                             handlebox)
            handle_list.append(handle)




            handleboxes.append(handlebox)


        if len(handleboxes) > 0:

            # We calculate number of lows in each column. The first
            # (num_largecol) columns will have (nrows+1) rows, and remaing
            # (num_smallcol) columns will have (nrows) rows.
            ncol = min(self._ncol, len(handleboxes))
            nrows, num_largecol = divmod(len(handleboxes), ncol)
            num_smallcol = ncol-num_largecol

            # starting index of each column and number of rows in it.
            largecol = safezip(range(0, num_largecol*(nrows+1), (nrows+1)),
                               [nrows+1] * num_largecol)
            smallcol = safezip(range(num_largecol*(nrows+1), len(handleboxes), nrows),
                               [nrows] * num_smallcol)
        else:
            largecol, smallcol = [], []

        handle_label = safezip(handleboxes, labelboxes)
        columnbox = []
        for i0, di in largecol+smallcol:
            # pack handleBox and labelBox into itemBox
#.........这里部分代码省略.........
开发者ID:EnochManohar,项目名称:matplotlib,代码行数:101,代码来源:legend.py

示例4: _init_legend_box

    def _init_legend_box(self, handles, labels, markerfirst=True):
        """
        Initialize the legend_box. The legend_box is an instance of
        the OffsetBox, which is packed with legend handles and
        texts. Once packed, their location is calculated during the
        drawing time.
        """

        fontsize = self._fontsize

        # legend_box is a HPacker, horizontally packed with
        # columns. Each column is a VPacker, vertically packed with
        # legend items. Each legend item is HPacker packed with
        # legend handleBox and labelBox. handleBox is an instance of
        # offsetbox.DrawingArea which contains legend handle. labelBox
        # is an instance of offsetbox.TextArea which contains legend
        # text.

        text_list = []  # the list of text instances
        handle_list = []  # the list of text instances

        label_prop = dict(verticalalignment='baseline',
                          horizontalalignment='left',
                          fontproperties=self.prop,
                          )

        labelboxes = []
        handleboxes = []

        # The approximate height and descent of text. These values are
        # only used for plotting the legend handle.
        descent = 0.35 * self._approx_text_height() * (self.handleheight - 0.7)
        # 0.35 and 0.7 are just heuristic numbers and may need to be improved.
        height = self._approx_text_height() * self.handleheight - descent
        # each handle needs to be drawn inside a box of (x, y, w, h) =
        # (0, -descent, width, height).  And their coordinates should
        # be given in the display coordinates.

        # The transformation of each handle will be automatically set
        # to self.get_trasnform(). If the artist does not use its
        # default transform (e.g., Collections), you need to
        # manually set their transform to the self.get_transform().
        legend_handler_map = self.get_legend_handler_map()

        for orig_handle, lab in zip(handles, labels):
            handler = self.get_legend_handler(legend_handler_map, orig_handle)
            if handler is None:
                warnings.warn(
                    "Legend does not support {!r} instances.\nA proxy artist "
                    "may be used instead.\nSee: "
                    "http://matplotlib.org/users/legend_guide.html"
                    "#using-proxy-artist".format(orig_handle)
                )
                # We don't have a handle for this artist, so we just defer
                # to None.
                handle_list.append(None)
            else:
                textbox = TextArea(lab, textprops=label_prop,
                                   multilinebaseline=True,
                                   minimumdescent=True)
                text_list.append(textbox._text)

                labelboxes.append(textbox)

                handlebox = DrawingArea(width=self.handlelength * fontsize,
                                        height=height,
                                        xdescent=0., ydescent=descent)
                handleboxes.append(handlebox)

                # Create the artist for the legend which represents the
                # original artist/handle.
                handle_list.append(handler.legend_artist(self, orig_handle,
                                                         fontsize, handlebox))

        if handleboxes:
            # We calculate number of rows in each column. The first
            # (num_largecol) columns will have (nrows+1) rows, and remaining
            # (num_smallcol) columns will have (nrows) rows.
            ncol = min(self._ncol, len(handleboxes))
            nrows, num_largecol = divmod(len(handleboxes), ncol)
            num_smallcol = ncol - num_largecol
            # starting index of each column and number of rows in it.
            rows_per_col = [nrows + 1] * num_largecol + [nrows] * num_smallcol
            start_idxs = np.concatenate([[0], np.cumsum(rows_per_col)[:-1]])
            cols = zip(start_idxs, rows_per_col)
        else:
            cols = []

        handle_label = list(zip(handleboxes, labelboxes))
        columnbox = []
        for i0, di in cols:
            # pack handleBox and labelBox into itemBox
            itemBoxes = [HPacker(pad=0,
                                 sep=self.handletextpad * fontsize,
                                 children=[h, t] if markerfirst else [t, h],
                                 align="baseline")
                         for h, t in handle_label[i0:i0 + di]]
            # minimumdescent=False for the text of the last row of the column
            if markerfirst:
                itemBoxes[-1].get_children()[1].set_minimumdescent(False)
#.........这里部分代码省略.........
开发者ID:LindyBalboa,项目名称:matplotlib,代码行数:101,代码来源:legend.py

示例5: Legend


#.........这里部分代码省略.........
                          )

        labelboxes = []
        handleboxes = []

        # The approximate height and descent of text. These values are
        # only used for plotting the legend handle.
        descent = 0.35 * self._approx_text_height() * (self.handleheight - 0.7)
        # 0.35 and 0.7 are just heuristic numbers and may need to be improved.
        height = self._approx_text_height() * self.handleheight - descent
        # each handle needs to be drawn inside a box of (x, y, w, h) =
        # (0, -descent, width, height).  And their coordinates should
        # be given in the display coordinates.

        # The transformation of each handle will be automatically set
        # to self.get_trasnform(). If the artist does not use its
        # default transform (e.g., Collections), you need to
        # manually set their transform to the self.get_transform().
        legend_handler_map = self.get_legend_handler_map()

        for orig_handle, lab in zip(handles, labels):
            handler = self.get_legend_handler(legend_handler_map, orig_handle)
            if handler is None:
                warnings.warn(
                    "Legend does not support {!r} instances.\nA proxy artist "
                    "may be used instead.\nSee: "
                    "http://matplotlib.org/users/legend_guide.html"
                    "#using-proxy-artist".format(orig_handle)
                )
                # We don't have a handle for this artist, so we just defer
                # to None.
                handle_list.append(None)
            else:
                textbox = TextArea(lab, textprops=label_prop,
                                   multilinebaseline=True,
                                   minimumdescent=True)
                text_list.append(textbox._text)

                labelboxes.append(textbox)

                handlebox = DrawingArea(width=self.handlelength * fontsize,
                                        height=height,
                                        xdescent=0., ydescent=descent)
                handleboxes.append(handlebox)

                # Create the artist for the legend which represents the
                # original artist/handle.
                handle_list.append(handler.legend_artist(self, orig_handle,
                                                         fontsize, handlebox))

        if handleboxes:
            # We calculate number of rows in each column. The first
            # (num_largecol) columns will have (nrows+1) rows, and remaining
            # (num_smallcol) columns will have (nrows) rows.
            ncol = min(self._ncol, len(handleboxes))
            nrows, num_largecol = divmod(len(handleboxes), ncol)
            num_smallcol = ncol - num_largecol
            # starting index of each column and number of rows in it.
            rows_per_col = [nrows + 1] * num_largecol + [nrows] * num_smallcol
            start_idxs = np.concatenate([[0], np.cumsum(rows_per_col)[:-1]])
            cols = zip(start_idxs, rows_per_col)
        else:
            cols = []

        handle_label = list(zip(handleboxes, labelboxes))
        columnbox = []
开发者ID:LindyBalboa,项目名称:matplotlib,代码行数:67,代码来源:legend.py

示例6: _init_legend_box

    def _init_legend_box(self, handles, labels):
        """
        Initiallize the legend_box. The legend_box is an instance of
        the OffsetBox, which is packed with legend handles and
        texts. Once packed, their location is calculated during the
        drawing time.
        """

        fontsize = self._fontsize

        # legend_box is a HPacker, horizontally packed with
        # columns. Each column is a VPacker, vertically packed with
        # legend items. Each legend item is HPacker packed with
        # legend handleBox and labelBox. handleBox is an instance of
        # offsetbox.DrawingArea which contains legend handle. labelBox
        # is an instance of offsetbox.TextArea which contains legend
        # text.


        text_list = []  # the list of text instances
        handle_list = []  # the list of text instances

        label_prop = dict(verticalalignment='baseline',
                          horizontalalignment='left',
                          fontproperties=self.prop,
                          )

        labelboxes = []

        for l in labels:
            textbox = TextArea(l, textprops=label_prop,
                               multilinebaseline=True, minimumdescent=True)
            text_list.append(textbox._text)
            labelboxes.append(textbox)

        handleboxes = []


        # The approximate height and descent of text. These values are
        # only used for plotting the legend handle.
        height = self._approx_text_height() * 0.7
        descent = 0.

        # each handle needs to be drawn inside a box of (x, y, w, h) =
        # (0, -descent, width, height).  And their corrdinates should
        # be given in the display coordinates.

        # The transformation of each handle will be automatically set
        # to self.get_trasnform(). If the artist does not uses its
        # default trasnform (eg, Collections), you need to
        # manually set their transform to the self.get_transform().

        for handle in handles:
            if isinstance(handle, RegularPolyCollection) or \
                   isinstance(handle, CircleCollection):
                npoints = self.scatterpoints
            else:
                npoints = self.numpoints
            if npoints > 1:
                # we put some pad here to compensate the size of the
                # marker
                xdata = np.linspace(0.3*fontsize,
                                    (self.handlelength-0.3)*fontsize,
                                    npoints)
                xdata_marker = xdata
            elif npoints == 1:
                xdata = np.linspace(0, self.handlelength*fontsize, 2)
                xdata_marker = [0.5*self.handlelength*fontsize]

            if isinstance(handle, Line2D):
                ydata = ((height-descent)/2.)*np.ones(xdata.shape, float)
                legline = Line2D(xdata, ydata)

                legline.update_from(handle)
                self._set_artist_props(legline) # after update
                legline.set_clip_box(None)
                legline.set_clip_path(None)
                legline.set_drawstyle('default')
                legline.set_marker('None')

                handle_list.append(legline)

                legline_marker = Line2D(xdata_marker, ydata[:len(xdata_marker)])
                legline_marker.update_from(handle)
                self._set_artist_props(legline_marker)
                legline_marker.set_clip_box(None)
                legline_marker.set_clip_path(None)
                legline_marker.set_linestyle('None')
                # we don't want to add this to the return list because
                # the texts and handles are assumed to be in one-to-one
                # correpondence.
                legline._legmarker = legline_marker

            elif isinstance(handle, Patch):
                p = Rectangle(xy=(0., 0.),
                              width = self.handlelength*fontsize,
                              height=(height-descent),
                              )
                p.update_from(handle)
                self._set_artist_props(p)
#.........这里部分代码省略.........
开发者ID:AndreI11,项目名称:SatStressGui,代码行数:101,代码来源:legend.py

示例7: Legend


#.........这里部分代码省略.........
        label_prop = dict(verticalalignment='baseline',
                          horizontalalignment='left',
                          fontproperties=self.prop,
                          )

        # The approximate height and descent of text. These values are
        # only used for plotting the legend handle.
        descent = 0.35 * self._approx_text_height() * (self.handleheight - 0.7)
        # 0.35 and 0.7 are just heuristic numbers and may need to be improved.
        height = self._approx_text_height() * self.handleheight - descent
        # each handle needs to be drawn inside a box of (x, y, w, h) =
        # (0, -descent, width, height).  And their coordinates should
        # be given in the display coordinates.

        # The transformation of each handle will be automatically set
        # to self.get_transform(). If the artist does not use its
        # default transform (e.g., Collections), you need to
        # manually set their transform to the self.get_transform().
        legend_handler_map = self.get_legend_handler_map()

        for orig_handle, lab in zip(handles, labels):
            handler = self.get_legend_handler(legend_handler_map, orig_handle)
            if handler is None:
                cbook._warn_external(
                    "Legend does not support {!r} instances.\nA proxy artist "
                    "may be used instead.\nSee: "
                    "http://matplotlib.org/users/legend_guide.html"
                    "#creating-artists-specifically-for-adding-to-the-legend-"
                    "aka-proxy-artists".format(orig_handle))
                # We don't have a handle for this artist, so we just defer
                # to None.
                handle_list.append(None)
            else:
                textbox = TextArea(lab, textprops=label_prop,
                                   multilinebaseline=True,
                                   minimumdescent=True)
                handlebox = DrawingArea(width=self.handlelength * fontsize,
                                        height=height,
                                        xdescent=0., ydescent=descent)

                text_list.append(textbox._text)
                # Create the artist for the legend which represents the
                # original artist/handle.
                handle_list.append(handler.legend_artist(self, orig_handle,
                                                         fontsize, handlebox))
                handles_and_labels.append((handlebox, textbox))

        if handles_and_labels:
            # We calculate number of rows in each column. The first
            # (num_largecol) columns will have (nrows+1) rows, and remaining
            # (num_smallcol) columns will have (nrows) rows.
            ncol = min(self._ncol, len(handles_and_labels))
            nrows, num_largecol = divmod(len(handles_and_labels), ncol)
            num_smallcol = ncol - num_largecol
            # starting index of each column and number of rows in it.
            rows_per_col = [nrows + 1] * num_largecol + [nrows] * num_smallcol
            start_idxs = np.concatenate([[0], np.cumsum(rows_per_col)[:-1]])
            cols = zip(start_idxs, rows_per_col)
        else:
            cols = []

        columnbox = []
        for i0, di in cols:
            # pack handleBox and labelBox into itemBox
            itemBoxes = [HPacker(pad=0,
                                 sep=self.handletextpad * fontsize,
开发者ID:jklymak,项目名称:matplotlib,代码行数:67,代码来源:legend.py

示例8: do_plot

    def do_plot(self, wallet, history):
        balance_Val=[]
#        fee_val=[]
        value_val=[]
        datenums=[]
        unknown_trans = 0
        pending_trans = 0
        for item in history:
            tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item
            if confirmations:
                if timestamp is not None:
                    try:
                        datenums.append(md.date2num(datetime.datetime.fromtimestamp(timestamp)))
                        balance_string = format_satoshis(balance, False, decimal_point=self.window.decimal_point)
                        balance_Val.append(float(balance_string))
                    except [RuntimeError, TypeError, NameError] as reason:
                        unknown_trans=unknown_trans+1
                        pass
                else:
                    unknown_trans=unknown_trans+1

                if value is not None:
                    value_string = format_satoshis(value, True, decimal_point=self.window.decimal_point)
                    value_val.append(float(value_string))
                else:
                    value_string = '--'
            else:
                pending_trans=pending_trans+1


#            if fee is not None:
#                fee_string = format_satoshis(fee, True)
#                fee_val.append(float(fee_string))
#            else:
#                fee_string = '0'

            if tx_hash:
                label, is_default_label = wallet.get_label(tx_hash)
                label = label.encode('utf-8')
            else:
                label = ""


        f, axarr = plt.subplots(2, sharex=True)

        plt.subplots_adjust(bottom=0.2)
        plt.xticks( rotation=25 )
        ax=plt.gca()
        x=19
        if unknown_trans > 0:
            test11="Unknown transactions =  "+str(unknown_trans)+" ."
            box1 = TextArea(" Test : Number of unkown transactions", textprops=dict(color="k"))
            box1.set_text(test11)


            box = HPacker(children=[box1],
                align="center",
                pad=0.1, sep=15)

            anchored_box = AnchoredOffsetbox(loc=3,
                child=box, pad=0.5,
                frameon=True,
                bbox_to_anchor=(0.5, 1.02),
                bbox_transform=ax.transAxes,
                borderpad=0.5,
            )


            ax.add_artist(anchored_box)


        plt.ylabel(self.window.base_unit())
        plt.xlabel('Dates')
        xfmt = md.DateFormatter('%Y-%m-%d')
        ax.xaxis.set_major_formatter(xfmt)


        axarr[0].plot(datenums,balance_Val,marker='o',linestyle='-',color='blue',label='Balance')
        axarr[0].legend(loc='upper left')
        axarr[0].set_title('Confirmed Balance History')


        xfmt = md.DateFormatter('%Y-%m-%d')
        ax.xaxis.set_major_formatter(xfmt)
        axarr[1].plot(datenums,value_val,marker='o',linestyle='-',color='green',label='Tx Value')
        axarr[1].legend(loc='upper left')
        axarr[1].set_title('Confirmed Transaction History')




     #   plt.annotate('unknown transaction = %d \n pending transactions = %d' %(unknown_trans,pending_trans),xy=(0.7,0.05),xycoords='axes fraction',size=12)
        plt.annotate('pending transactions = %d' %pending_trans,xy=(0.7,-0.45),xycoords='axes fraction',size=12)
        plt.show()
开发者ID:martexcoin,项目名称:encompass,代码行数:94,代码来源:plot.py

示例9: do_plot

    def do_plot(self, wallet):
        history = wallet.get_tx_history()
        balance_Val = []
        fee_val = []
        value_val = []
        datenums = []
        unknown_trans = 0
        pending_trans = 0
        counter_trans = 0
        for item in history:
            tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item
            if confirmations:
                if timestamp is not None:
                    try:
                        datenums.append(md.date2num(datetime.datetime.fromtimestamp(timestamp)))
                        balance_string = format_satoshis(balance, False)
                        balance_Val.append(float((format_satoshis(balance, False))) * 1000.0)
                    except [RuntimeError, TypeError, NameError] as reason:
                        unknown_trans = unknown_trans + 1
                        pass
                else:
                    unknown_trans = unknown_trans + 1
            else:
                pending_trans = pending_trans + 1

            if value is not None:
                value_string = format_satoshis(value, True)
                value_val.append(float(value_string) * 1000.0)
            else:
                value_string = "--"

            if fee is not None:
                fee_string = format_satoshis(fee, True)
                fee_val.append(float(fee_string))
            else:
                fee_string = "0"

            if tx_hash:
                label, is_default_label = wallet.get_label(tx_hash)
                label = label.encode("utf-8")
            else:
                label = ""

        f, axarr = plt.subplots(2, sharex=True)

        plt.subplots_adjust(bottom=0.2)
        plt.xticks(rotation=25)
        ax = plt.gca()
        x = 19
        test11 = (
            "Unknown transactions =  " + str(unknown_trans) + " Pending transactions =  " + str(pending_trans) + " ."
        )
        box1 = TextArea(" Test : Number of pending transactions", textprops=dict(color="k"))
        box1.set_text(test11)

        box = HPacker(children=[box1], align="center", pad=0.1, sep=15)

        anchored_box = AnchoredOffsetbox(
            loc=3,
            child=box,
            pad=0.5,
            frameon=True,
            bbox_to_anchor=(0.5, 1.02),
            bbox_transform=ax.transAxes,
            borderpad=0.5,
        )

        ax.add_artist(anchored_box)

        plt.ylabel("mBTC")
        plt.xlabel("Dates")
        xfmt = md.DateFormatter("%Y-%m-%d")
        ax.xaxis.set_major_formatter(xfmt)

        axarr[0].plot(datenums, balance_Val, marker="o", linestyle="-", color="blue", label="Balance")
        axarr[0].legend(loc="upper left")
        axarr[0].set_title("History Transactions")

        xfmt = md.DateFormatter("%Y-%m-%d")
        ax.xaxis.set_major_formatter(xfmt)
        axarr[1].plot(datenums, fee_val, marker="o", linestyle="-", color="red", label="Fee")
        axarr[1].plot(datenums, value_val, marker="o", linestyle="-", color="green", label="Value")

        axarr[1].legend(loc="upper left")
        #   plt.annotate('unknown transaction = %d \n pending transactions = %d' %(unknown_trans,pending_trans),xy=(0.7,0.05),xycoords='axes fraction',size=12)
        plt.show()
开发者ID:jimmysong,项目名称:electrum,代码行数:86,代码来源:plot.py


注:本文中的matplotlib.offsetbox.TextArea类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。