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


Python text.Annotation方法代码示例

本文整理汇总了Python中matplotlib.text.Annotation方法的典型用法代码示例。如果您正苦于以下问题:Python text.Annotation方法的具体用法?Python text.Annotation怎么用?Python text.Annotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.text的用法示例。


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

示例1: test_arrow_annotation_get_window_extent

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def test_arrow_annotation_get_window_extent():
    figure = Figure(dpi=100)
    figure.set_figwidth(2.0)
    figure.set_figheight(2.0)
    renderer = RendererAgg(200, 200, 100)

    # Text annotation with arrow
    annotation = Annotation(
        '', xy=(0.0, 50.0), xytext=(50.0, 50.0), xycoords='figure pixels',
        arrowprops={
            'facecolor': 'black', 'width': 8, 'headwidth': 10, 'shrink': 0.0})
    annotation.set_figure(figure)
    annotation.draw(renderer)

    bbox = annotation.get_window_extent()
    points = bbox.get_points()

    eq_(bbox.width, 50.0)
    assert_almost_equal(bbox.height, 10.0 / 0.72)
    eq_(points[0, 0], 0.0)
    eq_(points[0, 1], 50.0 - 5 / 0.72) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:23,代码来源:test_text.py

示例2: test_empty_annotation_get_window_extent

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def test_empty_annotation_get_window_extent():
    figure = Figure(dpi=100)
    figure.set_figwidth(2.0)
    figure.set_figheight(2.0)
    renderer = RendererAgg(200, 200, 100)

    # Text annotation with arrow
    annotation = Annotation(
        '', xy=(0.0, 50.0), xytext=(0.0, 50.0), xycoords='figure pixels')
    annotation.set_figure(figure)
    annotation.draw(renderer)

    bbox = annotation.get_window_extent()
    points = bbox.get_points()

    eq_(points[0, 0], 0.0)
    eq_(points[1, 0], 0.0)
    eq_(points[1, 1], 50.0)
    eq_(points[0, 1], 50.0) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:21,代码来源:test_text.py

示例3: _init_offsetText

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def _init_offsetText(self, direction):

        x,y,va,ha = self._offsetText_pos[direction]

        self.offsetText = mtext.Annotation("",
                                           xy=(x,y), xycoords="axes fraction",
                                           xytext=(0,0), textcoords="offset points",
                                           #fontproperties = fp,
                                           color = rcParams['xtick.color'],
                                           verticalalignment=va,
                                           horizontalalignment=ha,
                                           )
        self.offsetText.set_transform(IdentityTransform())
        self.axes._set_artist_props(self.offsetText) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:axis_artist.py

示例4: test_text_annotation_get_window_extent

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def test_text_annotation_get_window_extent():
    figure = Figure(dpi=100)
    renderer = RendererAgg(200, 200, 100)

    # Only text annotation
    annotation = Annotation('test', xy=(0, 0))
    annotation.set_figure(figure)

    text = Text(text='test', x=0, y=0)
    text.set_figure(figure)

    bbox = annotation.get_window_extent(renderer=renderer)

    text_bbox = text.get_window_extent(renderer=renderer)
    eq_(bbox.width, text_bbox.width)
    eq_(bbox.height, text_bbox.height)

    _, _, d = renderer.get_text_width_height_descent(
        'text', annotation._fontproperties, ismath=False)
    _, _, lp_d = renderer.get_text_width_height_descent(
        'lp', annotation._fontproperties, ismath=False)
    below_line = max(d, lp_d)

    # These numbers are specific to the current implementation of Text
    points = bbox.get_points()
    eq_(points[0, 0], 0.0)
    eq_(points[1, 0], text_bbox.width)
    eq_(points[0, 1], -below_line)
    eq_(points[1, 1], text_bbox.height - below_line) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:31,代码来源:test_text.py

示例5: _init_offsetText

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def _init_offsetText(self, direction):

        x,y,va,ha = self._offsetText_pos[direction]

        self.offsetText = mtext.Annotation("",
                                           xy=(x,y), xycoords="axes fraction",
                                           xytext=(0,0), textcoords="offset points",
                                           color = rcParams['xtick.color'],
                                           verticalalignment=va,
                                           horizontalalignment=ha,
                                           )
        self.offsetText.set_transform(IdentityTransform())
        self.axes._set_artist_props(self.offsetText) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:15,代码来源:axis_artist.py

示例6: _init_offsetText

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def _init_offsetText(self, direction):
        x, y, va, ha = self._offsetText_pos[direction]
        self.offsetText = mtext.Annotation(
            "",
            xy=(x, y), xycoords="axes fraction",
            xytext=(0, 0), textcoords="offset points",
            color=rcParams['xtick.color'],
            horizontalalignment=ha, verticalalignment=va,
        )
        self.offsetText.set_transform(IdentityTransform())
        self.axes._set_artist_props(self.offsetText) 
开发者ID:boris-kz,项目名称:CogAlg,代码行数:13,代码来源:axis_artist.py

示例7: export

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def export(self, decision_tree, ax=None):
        import matplotlib.pyplot as plt
        from matplotlib.text import Annotation
        if ax is None:
            ax = plt.gca()
        ax.clear()
        ax.set_axis_off()
        my_tree = self._make_tree(0, decision_tree.tree_)
        draw_tree = buchheim(my_tree)

        # important to make sure we're still
        # inside the axis after drawing the box
        # this makes sense because the width of a box
        # is about the same as the distance between boxes
        max_x, max_y = draw_tree.max_extents() + 1
        ax_width = ax.get_window_extent().width
        ax_height = ax.get_window_extent().height

        scale_x = ax_width / max_x
        scale_y = ax_height / max_y

        self.recurse(draw_tree, decision_tree.tree_, ax,
                     scale_x, scale_y, ax_height)

        anns = [ann for ann in ax.get_children()
                if isinstance(ann, Annotation)]

        # update sizes of all bboxes
        renderer = ax.figure.canvas.get_renderer()

        for ann in anns:
            ann.update_bbox_position_size(renderer)

        if self.fontsize is None:
            # get figure to data transform
            # adjust fontsize to avoid overlap
            # get max box width and height
            try:
                extents = [ann.get_bbox_patch().get_window_extent()
                           for ann in anns]
                max_width = max([extent.width for extent in extents])
                max_height = max([extent.height for extent in extents])
                # width should be around scale_x in axis coordinates
                size = anns[0].get_fontsize() * min(scale_x / max_width,
                                                    scale_y / max_height)
                for ann in anns:
                    ann.set_fontsize(size)
            except AttributeError:
                # matplotlib < 1.5
                warnings.warn("Automatic scaling of tree plots requires "
                              "matplotlib 1.5 or higher. Please specify "
                              "fontsize.")

        return anns 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:56,代码来源:export.py

示例8: on_pick

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def on_pick(self, event):
        artist = event.artist
        if not artist.get_visible():
            return
        for idx, artist_set in enumerate(self.pick_sets):
            if artist in artist_set:
                self.pick_funs[idx](artist)
                return

        if isinstance(artist, Line2D):
            mevent = event.mouseevent
            # figure out if we picked marker or line
            self.drag_idx = self._get_idx_under_point(mevent)

            if self.drag_idx >= 0:
                # picked marker.
                ax = mevent.inaxes
                an, pt, _, _ = self.markers[self.drag_idx]
                an.set_visible(False)
                pt.set_visible(False)
                self.canvas.draw()
                self.markers[self.drag_idx][-1] = self.canvas.copy_from_bbox(ax.bbox)
                an.set_visible(True)
                pt.set_visible(True)
                ax.draw_artist(an)
                ax.draw_artist(pt)
                self.canvas.blit(ax.bbox)

            else:
                # save data to plot marker later
                mxval = mevent.xdata
                button = mevent.button
                if mxval is not None and button == 1 and not self.marker_line_info:
                    self.marker_line_info = (artist, mxval, mevent.ydata,
                                             button, mevent.inaxes)
        elif isinstance(artist, Annotation):
            # delete marker.
            mevent = event.mouseevent
            if mevent.button == 3:
                targ_idx = None
                for idx, (an, pt, _, _) in enumerate(self.markers):
                    if an is artist:
                        targ_idx = idx
                        break
                if targ_idx is not None:
                    an, pt, _, _ = self.markers[targ_idx]
                    del self.markers[targ_idx]
                    an.set_visible(False)
                    pt.set_visible(False)
                    self.canvas.draw() 
开发者ID:ucb-art,项目名称:BAG_framework,代码行数:52,代码来源:plot.py

示例9: add_labels

# 需要导入模块: from matplotlib import text [as 别名]
# 或者: from matplotlib.text import Annotation [as 别名]
def add_labels(self, labels: List[str]) -> List["Text"]:
        """
        Updates background, adds text.
        Do NOT call after calling self.add_lines().
        """
        nlabel = len(labels)
        if nlabel != self.nplots:
            raise ValueError(
                f"incorrect labels: {self.nplots} plots but {nlabel} labels"
            )

        cfg = self.cfg
        color = cfg.get_label_color

        size_pt = cfg.label_font.size
        distance_px = cfg.label_padding_ratio * size_pt

        @attr.dataclass
        class AxisPosition:
            pos_axes: float
            offset_px: float
            align: str

        xpos = cfg.label_position.x.match(
            left=AxisPosition(0, distance_px, "left"),
            right=AxisPosition(1, -distance_px, "right"),
        )
        ypos = cfg.label_position.y.match(
            bottom=AxisPosition(0, distance_px, "bottom"),
            top=AxisPosition(1, -distance_px, "top"),
        )

        pos_axes = (xpos.pos_axes, ypos.pos_axes)
        offset_pt = (xpos.offset_px, ypos.offset_px)

        out: List["Text"] = []
        for label_text, ax in zip(labels, self._axes_mono):
            # https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.annotate.html
            # Annotation subclasses Text.
            text: "Annotation" = ax.annotate(
                label_text,
                # Positioning
                xy=pos_axes,
                xycoords="axes fraction",
                xytext=offset_pt,
                textcoords="offset points",
                horizontalalignment=xpos.align,
                verticalalignment=ypos.align,
                # Cosmetics
                color=color,
                fontsize=px_from_points(size_pt),
                fontfamily=cfg.label_font.family,
                fontweight=("bold" if cfg.label_font.bold else "normal"),
                fontstyle=("italic" if cfg.label_font.italic else "normal"),
            )
            out.append(text)

        self._save_background()
        return out

    # Output frames 
开发者ID:corrscope,项目名称:corrscope,代码行数:63,代码来源:renderer.py


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