How to use the svgutils.transform 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 / src / svgutils / compose.py View on Github external
def __init__(self, fname=None):
        if fname:
            fname = os.path.join(CONFIG['svg.file_path'], fname)
            svg = _transform.fromfile(fname)
            self.root = svg.getroot().root
github chrisjbillington / git_nautilus_icons / icons / generate_icons.py View on Github external
# For each git icon, make an icon for the case where it is ahead:
ahead_icons = [(ahead, repo, bl, br) for _, repo, bl, br in repo_icons]

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)
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
github gkichaev / PAINTOR_V3.0 / CANVIS / CANVIS.py View on Github external
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')
                plot4 = plot4.getroot()

                #transform and add heatmap figure; must be added first for correct layering
                if horizontal=='y':
                    y_scale = len_annotation_plot + size_prob_plot +size_heatmap*heatmap_count+ 75
                    plot4.moveto(375,y_scale, scale=1.40)
                    plot4.rotate(-45, 0, 0)
                    fig.append(plot4)
                    x_move = 510
            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)