def join(self, verbose=True): """ join :class:`matplotlib.figure.Figure` objects contained in the object. Currently supports only joining into a single horizontal row. ARGS: verbose (boolean): if True, print a message to stdout as each figure is added to the SVG file. .. warning:: for now assumes that all figures are the same size. """ # TODO ([email protected]): sniff out the figure sizes and # size the SVG figure to accommodate all the figures. # TODO ([email protected]): allow user to specify rows, # columns of combined SVG figures. layout = VerticalLayout() sz = map(int, sg.from_mpl(self.figs[0]).get_size()) sz[1] *= len(self.figs) sz = map(str, sz) layout.set_size(sz) for f in self.figs: layout.add_figure(sg.from_mpl(f)) if verbose: print('saving {}'.format(self.fname_svg)) layout.save(self.fname_svg)
import numpy as np import os import os.path try: figs = [] for i in range(2): figs.append(plt.figure()) plt.plot(np.random.random(100)) layout = VerticalLayout() sz = map(int, sg.from_mpl(figs[0]).get_size()) sz[1] *= 3 sz = map(str, sz) layout.set_size(sz) layout.add_figure(sg.from_mpl(figs[0])) layout.add_figure(sg.from_mpl(figs[1])) txt1 = sg.TextElement(50, 50, "HELLO", size=12) layout.append([txt1]) layout.save(os.path.join('/', 'tmp', 'stack_plots.svg')) try: print('converting to pdf') subprocess.call( '/Applications/Inkscape.app/Contents/Resources/bin/inkscape --export-pdf=/tmp/stack_plots.pdf /tmp/stack_plots.svg', shell=True) except: print('unable to run inkscape') finally: plt.close('all')
#!/usr/bin/env python # coding=utf-8 import numpy as np import matplotlib.pyplot as plt from svgutils.transform import from_mpl from svgutils.templates import VerticalLayout layout = VerticalLayout() fig1 = plt.figure() plt.plot([1, 2]) fig2 = plt.figure() plt.plot([2, 1]) layout.add_figure(from_mpl(fig1)) layout.add_figure(from_mpl(fig2)) layout.save("stack_plots.svg")
#!/usr/bin/env python #coding=utf-8 import numpy as np import matplotlib.pyplot as plt from svgutils.transform import from_mpl from svgutils.templates import VerticalLayout layout = VerticalLayout() fig1 = plt.figure() plt.plot([1,2]) fig2 = plt.figure() plt.plot([2,1]) layout.add_figure(from_mpl(fig1)) layout.add_figure(from_mpl(fig2)) print(from_mpl(fig1).get_size()) layout.save('stack_plots.svg')
#!/usr/bin/env python #coding=utf-8 import numpy as np import matplotlib.pyplot as plt from svgutils.transform import from_mpl from svgutils.templates import VerticalLayout layout = VerticalLayout() fig1 = plt.figure() plt.plot([1,2]) fig2 = plt.figure() plt.plot([2,1]) layout.add_figure(from_mpl(fig1)) layout.add_figure(from_mpl(fig2)) print from_mpl(fig1).get_size() layout.save('stack_plots.svg')
from svgutils.templates import VerticalLayout import matplotlib.pyplot as plt import numpy as np import os import os.path try: figs = [] for i in range(2): figs.append(plt.figure()) plt.plot(np.random.random(100)) layout = VerticalLayout() sz = map(int, sg.from_mpl(figs[0]).get_size()) sz[1] *= 3 sz = map(str, sz) layout.set_size(sz) layout.add_figure(sg.from_mpl(figs[0])) layout.add_figure(sg.from_mpl(figs[1])) txt1 = sg.TextElement(50, 50, "HELLO", size=12) layout.append([txt1]) layout.save(os.path.join('/', 'tmp', 'stack_plots.svg')) try: print('converting to pdf') subprocess.call('/Applications/Inkscape.app/Contents/Resources/bin/inkscape --export-pdf=/tmp/stack_plots.pdf /tmp/stack_plots.svg', shell=True) except: print('unable to run inkscape') finally: plt.close('all')