當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。