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


Python textpath.TextPath方法代码示例

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


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

示例1: plt_draw_text

# 需要导入模块: from matplotlib import textpath [as 别名]
# 或者: from matplotlib.textpath import TextPath [as 别名]
def plt_draw_text(node: minidom.Element, trans: mtransforms.Transform, style: dict, ids: dict, no_draw: bool = False):
    """ draw a svg text node as a text patch element into the figure (with the given transformation and style) """
    trans = parseTransformation(node.getAttribute("transform")) + trans + plt.gca().transData
    trans = mtransforms.Affine2D([[1, 0, 0], [0, -1, 0], [0, 0, 1]]) + trans
    pos = np.array([svgUnitToMpl(node.getAttribute("x")), -svgUnitToMpl(node.getAttribute("y"))])

    style = get_inline_style(node, get_css_style(node, ids["css"], style))

    text_content = ""
    patch_list = []
    for child in node.childNodes:
        text_content += child.firstChild.nodeValue
        if 1:
            style_child = get_inline_style(child, get_css_style(child, ids["css"], style))
            pos_child = pos.copy()
            if child.getAttribute("x") != "":
                pos_child = np.array([svgUnitToMpl(child.getAttribute("x")), -svgUnitToMpl(child.getAttribute("y"))])
            if child.getAttribute("dx") != "":
                pos_child[0] += svgUnitToMpl(child.getAttribute("dx"))
            if child.getAttribute("dy") != "":
                pos_child[1] -= svgUnitToMpl(child.getAttribute("dy"))
            path1 = TextPath(pos_child,
                             child.firstChild.nodeValue,
                             prop=font_properties_from_style(style_child))
            patch = mpatches.PathPatch(path1, transform=trans)

            apply_style(style_child, patch)
            if not no_draw and not styleNoDisplay(style_child):
                plt.gca().add_patch(patch)
            if child.getAttribute("id") != "":
                ids[child.getAttribute("id")] = patch
            patch_list.append(patch)
        else:
            text = plt.text(float(child.getAttribute("x")), float(child.getAttribute("y")),
                     child.firstChild.nodeValue,
                     transform=trans)
            apply_style(style, text)

    if node.getAttribute("id") != "":
        ids[node.getAttribute("id")] = patch_list 
开发者ID:rgerum,项目名称:pylustrator,代码行数:42,代码来源:parse_svg.py

示例2: _add_watermark

# 需要导入模块: from matplotlib import textpath [as 别名]
# 或者: from matplotlib.textpath import TextPath [as 别名]
def _add_watermark(self, fig, axes, figsize, text, dpi=300, size_scale=1.0):  # pragma: no cover
        # Code based off github repository https://github.com/cpadavis/preliminize
        dx, dy = figsize
        dy, dx = dy * dpi, dx * dpi
        rotation = 180 / np.pi * np.arctan2(-dy, dx)
        fontdict = self.parent.config["watermark_text_kwargs"]
        if "usetex" in fontdict:
            usetex = fontdict["usetex"]
        else:
            usetex = self.parent.config["usetex"]
            fontdict["usetex"] = usetex
        if fontdict["usetex"]:
            px, py, scale = 0.5, 0.5, 1.0
        else:
            px, py, scale = 0.45, 0.55, 0.8
        bb0 = TextPath((0, 0), text, size=50, props=fontdict, usetex=usetex).get_extents()
        bb1 = TextPath((0, 0), text, size=51, props=fontdict, usetex=usetex).get_extents()
        dw = (bb1.width - bb0.width) * (dpi / 100)
        dh = (bb1.height - bb0.height) * (dpi / 100)
        size = np.sqrt(dy ** 2 + dx ** 2) / (dh * abs(dy / dx) + dw) * 0.6 * scale * size_scale
        if axes is not None:
            if fontdict["usetex"]:
                size *= 0.7
            else:
                size *= 0.85
        fontdict["size"] = int(size)
        if axes is None:
            fig.text(px, py, text, fontdict=fontdict, rotation=rotation)
        else:
            axes.text(px, py, text, transform=axes.transAxes, fontdict=fontdict, rotation=rotation) 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:32,代码来源:plotter.py

示例3: _get_size_of_texts

# 需要导入模块: from matplotlib import textpath [as 别名]
# 或者: from matplotlib.textpath import TextPath [as 别名]
def _get_size_of_texts(self, texts):  # pragma: no cover
        usetex = self.parent.config["usetex"]
        size = self.parent.config["label_font_size"]
        widths = [TextPath((0, 0), text, usetex=usetex, size=size).get_extents().width for text in texts]
        return max(widths) 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:7,代码来源:plotter.py

示例4: _text_path

# 需要导入模块: from matplotlib import textpath [as 别名]
# 或者: from matplotlib.textpath import TextPath [as 别名]
def _text_path(text: str, font: FontProperties) -> TextPath:
    return TextPath((0, 0), text, size=1, prop=font) 
开发者ID:mozman,项目名称:ezdxf,代码行数:4,代码来源:matplotlib_backend.py

示例5: render_text

# 需要导入模块: from matplotlib import textpath [as 别名]
# 或者: from matplotlib.textpath import TextPath [as 别名]
def render_text(text, size=None, position=(0, 0), font_prop=None, tolerance=0.1):
    path = TextPath(position, text, size=size, prop=font_prop)
    polys = []
    xmax = position[0]
    for points, code in path.iter_segments():
        if code == path.MOVETO:
            c = gdspy.Curve(*points, tolerance=tolerance)
        elif code == path.LINETO:
            c.L(*points)
        elif code == path.CURVE3:
            c.Q(*points)
        elif code == path.CURVE4:
            c.C(*points)
        elif code == path.CLOSEPOLY:
            poly = c.get_points()
            if poly.size > 0:
                if poly[:, 0].min() < xmax:
                    i = len(polys) - 1
                    while i >= 0:
                        if gdspy.inside(
                            poly[:1], [polys[i]], precision=0.1 * tolerance
                        )[0]:
                            p = polys.pop(i)
                            poly = gdspy.boolean(
                                [p],
                                [poly],
                                "xor",
                                precision=0.1 * tolerance,
                                max_points=0,
                            ).polygons[0]
                            break
                        elif gdspy.inside(
                            polys[i][:1], [poly], precision=0.1 * tolerance
                        )[0]:
                            p = polys.pop(i)
                            poly = gdspy.boolean(
                                [p],
                                [poly],
                                "xor",
                                precision=0.1 * tolerance,
                                max_points=0,
                            ).polygons[0]
                        i -= 1
                xmax = max(xmax, poly[:, 0].max())
                polys.append(poly)
    return polys 
开发者ID:heitzmann,项目名称:gdspy,代码行数:48,代码来源:fonts.py


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