How to use the svgutils.transform.fromfile 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 / docs / source / tutorials / fig_final.py View on Github external
import svgutils.transform as sg
import sys 

#create new SVG figure
fig = sg.SVGFigure("16cm", "6.5cm")

# load matpotlib-generated figures
fig1 = sg.fromfile('sigmoid_fit.svg')
fig2 = sg.fromfile('anscombe.svg')

# get the plot objects
plot1 = fig1.getroot()
plot2 = fig2.getroot()
plot2.moveto(280, 0, scale=0.5)

# add text labels
txt1 = sg.TextElement(25,20, "A", size=12, weight="bold")
txt2 = sg.TextElement(305,20, "B", size=12, weight="bold")

# append plots and labels to figure
fig.append([plot1, plot2])
fig.append([txt1, txt2])

# save generated SVG files
fig.save("fig_final.svg")
github gkichaev / PAINTOR_V3.0 / CANVIS / CANVIS.py View on Github external
if heatmaps == None:
        horizontal = 'n'
    elif len(heatmaps)>1:
        horizontal='y'

    if horizontal == 'y':
        size_width = "9in"
        size_height = '9in'
    else:
        size_width = "5in"
        size_height = '11in'

    fig = sg.SVGFigure(size_width, size_height)
    value_plots.savefig('value_plots.svg', format='svg', dpi=DPI, transparent=True)
    value_plots = sg.fromfile('value_plots.svg')
    plot1 = value_plots.getroot()
    if annotation_plot is not None:
        len_ann_plot = (len(annotation_plot))
    else:
        len_ann_plot = 0
    plot1.moveto(0, 0)
    fig.append(plot1)
    # plot heatmap(s)
    len_annotation_plot = size_annotation_plot * (len_ann_plot + 1)
    if heatmaps is not None:
        heatmap_count = 0
        for heatmap in heatmaps:
            plot4 = heatmap[0]
            try:
                plot4.savefig('heatmap.svg', format='svg', dpi=DPI, transparent=True)
                plot4 = sg.fromfile('heatmap.svg')
github chrisjbillington / git_nautilus_icons / icons / generate_icons.py View on Github external
try:
    shutil.rmtree('hicolor')
except FileNotFoundError:
    pass
    
os.system('mkdir -p hicolor/scalable/emblems/')
for tl, tr, bl, br in all_icons:
    # create new SVG figure
    background_image = sg.SVGFigure(32, 32)
    if bl is not None:
        bl_file = 'sub_icons/{}-l.svg'.format(bl)
        bl_image = sg.fromfile(bl_file).getroot()
        background_image.append(bl_image)
    if br is not None:
        br_file = 'sub_icons/{}-r.svg'.format(br)
        br_image = sg.fromfile(br_file).getroot()
        background_image.append(br_image)
    if tr is not None:
        tr_file = 'sub_icons/{}.svg'.format(tr)
        tr_image = sg.fromfile(tr_file).getroot()
        background_image.append(tr_image)
    if tl is not None:
        tl_file = 'sub_icons/{}.svg'.format(tl)
        tl_image = sg.fromfile(tl_file).getroot()
        background_image.append(tl_image)
    filename = '-'.join([name for name in (tl, tr, bl, br) if name is not None])
    filename = 'hicolor/scalable/emblems/git-{}.svg'.format(filename)
    background_image.save(filename)

# Simplified icons for the 16x16 size. Only shows a single icon for the worktree part of
# the status.
os.system('mkdir -p hicolor/16x16/emblems/')
github chrisjbillington / git_nautilus_icons / icons / generate_icons.py View on Github external
background_image = sg.SVGFigure(32, 32)
    if bl is not None:
        bl_file = 'sub_icons/{}-l.svg'.format(bl)
        bl_image = sg.fromfile(bl_file).getroot()
        background_image.append(bl_image)
    if br is not None:
        br_file = 'sub_icons/{}-r.svg'.format(br)
        br_image = sg.fromfile(br_file).getroot()
        background_image.append(br_image)
    if tr is not None:
        tr_file = 'sub_icons/{}.svg'.format(tr)
        tr_image = sg.fromfile(tr_file).getroot()
        background_image.append(tr_image)
    if tl is not None:
        tl_file = 'sub_icons/{}.svg'.format(tl)
        tl_image = sg.fromfile(tl_file).getroot()
        background_image.append(tl_image)
    filename = '-'.join([name for name in (tl, tr, bl, br) if name is not None])
    filename = 'hicolor/scalable/emblems/git-{}.svg'.format(filename)
    background_image.save(filename)

# Simplified icons for the 16x16 size. Only shows a single icon for the worktree part of
# the status.
os.system('mkdir -p hicolor/16x16/emblems/')
for tl, tr, bl, br in all_icons:
    # create new SVG figure
    background_image = sg.SVGFigure(32, 32)
    if 'unmerged' in br:
        br_file = 'sub_icons/unmerged-simple.svg'
    else:
        br_file = 'sub_icons/{}-r.svg'.format(br)
    br_image = sg.fromfile(br_file).getroot()
github gkichaev / PAINTOR_V3.0 / CANVIS / CANVIS.py View on Github external
except Exception as e:
                print('generate heatmap error')
                print(e)

            else:
                y_scale = size_stat_plot*len(zscore_plots) + (size_heatmap+1) * heatmap_count + len_annotation_plot + size_prob_plot + 110
                plot4.moveto(0,y_scale, scale=1.40)
                plot4.rotate(-45, 0, 0)
                fig.append(plot4)
                x_move=110

            heatmap_count = heatmap_count + 1
        colorbar_h = heatmap[1]
        try:
            colorbar_h.savefig('colorbar_h.svg', format='svg', dpi=DPI, transparent=True)
            colorbar_h = sg.fromfile('colorbar_h.svg')
            colorbar_h = colorbar_h.getroot()
            colorbar_h.moveto(x_move, y_scale + size_heatmap)
            fig.append(colorbar_h)
        except Exception as e:
            print('generate colorbar_h error')
            print(e)


    if annotation_plot is not None:
        # transform and add annotations plots
        index = 0
        for plot in annotation_plot:
            plot.savefig('annotation_plot.svg', format='svg', dpi=DPI, transparent=True)
            plot = sg.fromfile('annotation_plot.svg')
            plot3 = plot.getroot()
            y_move = size_prob_plot + size_annotation_plot * (index + 1)
github gkichaev / PAINTOR_V3.0 / CANVIS / CANVIS.py View on Github external
colorbar_h.savefig('colorbar_h.svg', format='svg', dpi=DPI, transparent=True)
            colorbar_h = sg.fromfile('colorbar_h.svg')
            colorbar_h = colorbar_h.getroot()
            colorbar_h.moveto(x_move, y_scale + size_heatmap)
            fig.append(colorbar_h)
        except Exception as e:
            print('generate colorbar_h error')
            print(e)


    if annotation_plot is not None:
        # transform and add annotations plots
        index = 0
        for plot in annotation_plot:
            plot.savefig('annotation_plot.svg', format='svg', dpi=DPI, transparent=True)
            plot = sg.fromfile('annotation_plot.svg')
            plot3 = plot.getroot()
            y_move = size_prob_plot + size_annotation_plot * (index + 1)
            plot3.moveto(30, y_move, scale=1.05)
            index += 1
            fig.append(plot3)

    #transform and add zscore plots
    index = 1

    for plot in zscore_plots:
        plot2 = plot[0]
        plot2.savefig('stats_plot.svg', format='svg', dpi=DPI, transparent=True)
        plot2 = sg.fromfile('stats_plot.svg')
        plot2 = plot2.getroot()
        y_move = size_stat_plot * index + len_annotation_plot
        index += 1
github gkichaev / PAINTOR_V3.0 / CANVIS / CANVIS.py View on Github external
plot2 = plot[0]
        plot2.savefig('stats_plot.svg', format='svg', dpi=DPI, transparent=True)
        plot2 = sg.fromfile('stats_plot.svg')
        plot2 = plot2.getroot()
        y_move = size_stat_plot * index + len_annotation_plot
        index += 1
        plot2.moveto(0, y_move)
        fig.append(plot2)


    # extract colorbar
    y_move = size_stat_plot * len(zscore_plots) + len_annotation_plot + size_prob_plot
    plot = zscore_plots[0]
    colorbar = plot[1]
    colorbar.savefig('colorbar.svg', format='svg', dpi=DPI, transparent=True)
    colorbar = sg.fromfile('colorbar.svg')
    colorbar = colorbar.getroot()
    colorbar.moveto(100, y_move +40)
    fig.append(colorbar)

    #export final figure as a svg and pdf
    #svgfile = "canvis.svg"
    svgfile = output + '.svg'
    fig.save(svgfile)


    """ Uncomment if want to convert to PDF. Note: must have CarioSVG libraries installed

    pdffile = output + ".pdf"
    cairosvg.svg2pdf(url=svgfile, write_to=pdffile)

    """
github chrisjbillington / git_nautilus_icons / icons / generate_icons.py View on Github external
dotgit_icon = [(None, None, None, dotgit)] 
# Put them all together:
all_icons = unstaged_icons + staged_icons + unmerged_icons + repo_icons + ahead_icons + dotgit_icon

try:
    shutil.rmtree('hicolor')
except FileNotFoundError:
    pass
    
os.system('mkdir -p hicolor/scalable/emblems/')
for tl, tr, bl, br in all_icons:
    # create new SVG figure
    background_image = sg.SVGFigure(32, 32)
    if bl is not None:
        bl_file = 'sub_icons/{}-l.svg'.format(bl)
        bl_image = sg.fromfile(bl_file).getroot()
        background_image.append(bl_image)
    if br is not None:
        br_file = 'sub_icons/{}-r.svg'.format(br)
        br_image = sg.fromfile(br_file).getroot()
        background_image.append(br_image)
    if tr is not None:
        tr_file = 'sub_icons/{}.svg'.format(tr)
        tr_image = sg.fromfile(tr_file).getroot()
        background_image.append(tr_image)
    if tl is not None:
        tl_file = 'sub_icons/{}.svg'.format(tl)
        tl_image = sg.fromfile(tl_file).getroot()
        background_image.append(tl_image)
    filename = '-'.join([name for name in (tl, tr, bl, br) if name is not None])
    filename = 'hicolor/scalable/emblems/git-{}.svg'.format(filename)
    background_image.save(filename)