How to use the svgutils.transform.fromstring function in svgutils

To help you get started, we’ve selected a few svgutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github btel / svg_utils / tests / test_transform.py View on Github external
def test_group_class():
    svg_fig = transform.fromstring(circle)
    group = svg_fig.getroot()
    ok_((group.root.attrib['class'] == 'main'))
github btel / svg_utils / tests / test_transform.py View on Github external
def test_skew():
    svg_fig = transform.fromstring(circle)
    group = svg_fig.getroot()

    # Test skew in y-axis
    group.skew(0, 30)
    ok_('skewY(30' in group.root.get('transform'))

    # Test skew in x-axis
    group.skew(30, 0)
    ok_('skewX(30' in group.root.get('transform'))
github btel / svg_utils / tests / test_transform.py View on Github external
def test_get_size():
    svg_fig = transform.fromstring(circle)
    w, h = svg_fig.get_size()
    ok_((w=='150') & (h=='50'))
github btel / svg_utils / tests / test_transform.py View on Github external
def test_scale_xy():
    svg_fig = transform.fromstring(circle)
    group = svg_fig.getroot()

    group.scale_xy(0, 30)
    ok_('scale(0' in group.root.get('transform'))
github poldracklab / mriqc / mriqc / viz / svg.py View on Github external
def combine_svg(svg_list, axis="vertical"):
    """
    Composes the input svgs into one standalone svg
    """
    import numpy as np
    import svgutils.transform as svgt

    # Read all svg files and get roots
    svgs = [svgt.fromstring(f.encode("utf-8")) for f in svg_list]
    roots = [f.getroot() for f in svgs]

    # Query the size of each
    sizes = [(int(f.width[:-2]), int(f.height[:-2])) for f in svgs]

    if axis == "vertical":
        # Calculate the scale to fit all widths
        scales = [1.0] * len(svgs)
        if not all([width[0] == sizes[0][0] for width in sizes[1:]]):
            ref_size = sizes[0]
            for i, els in enumerate(sizes):
                scales[i] = ref_size[0] / els[0]

        newsizes = [
            tuple(size) for size in np.array(sizes) * np.array(scales)[..., np.newaxis]
        ]
github poldracklab / niworkflows / niworkflows / viz / utils.py View on Github external
bbox_nii = nb.load(image_nii if bbox_nii is None else bbox_nii)
    if masked:
        bbox_nii = nlimage.threshold_img(bbox_nii, 1e-3)

    cuts = cuts_from_bbox(bbox_nii, cuts=7)
    plot_params["colors"] = colors or plot_params.get("colors", None)
    out_files = []
    for d in plot_params.pop("dimensions", ("z", "x", "y")):
        plot_params["display_mode"] = d
        plot_params["cut_coords"] = cuts[d]
        svg = _plot_anat_with_contours(
            image_nii, segs=seg_niis, compress=compress, **plot_params
        )
        # Find and replace the figure_1 id.
        svg = svg.replace("figure_1", "segmentation-%s-%s" % (d, uuid4()), 1)
        out_files.append(fromstring(svg))

    return out_files
github poldracklab / niworkflows / niworkflows / viz / utils.py View on Github external
# Generate nilearn figure
        display = plot_anat(anat_nii, **plot_params)
        if ribbon:
            kwargs = {"levels": [0.5], "linewidths": 0.5}
            display.add_contours(white, colors="b", **kwargs)
            display.add_contours(pial, colors="r", **kwargs)
        elif contour is not None:
            display.add_contours(contour, colors="b", levels=[0.5], linewidths=0.5)

        svg = extract_svg(display, compress=compress)
        display.close()

        # Find and replace the figure_1 id.
        svg = svg.replace("figure_1", "%s-%s-%s" % (div_id, mode, uuid4()), 1)
        out_files.append(fromstring(svg))

    return out_files