Exemplo n.º 1
0
def test_graphics():
    f = Figure(data=None, position=None)

    f.add_image(filename='', width=r'0.8\textwidth', placement=r'\centering')

    f.add_caption(caption='')
    repr(f)

    # Subfigure
    s = SubFigure(data=None, position=None, width=r'0.45\linewidth')

    s.add_image(filename='', width='r\linewidth',
                placement=None)

    s.add_caption(caption='')
    repr(s)

    # Matplotlib
    plot = Figure(data=None, position=None)

    x = [0, 1, 2, 3, 4, 5, 6]
    y = [15, 2, 7, 1, 5, 6, 9]

    pyplot.plot(x, y)

    plot.add_plot(width=r'0.8\textwidth', placement=r'\centering')
    plot.add_caption(caption='I am a caption.')
    repr(plot)
Exemplo n.º 2
0
def test_graphics():
    f = Figure(data=None, position=None)

    f.add_image(filename='', width=r'0.8\textwidth', placement=r'\centering')

    f.add_caption(caption='')
    repr(f)

    # Subfigure
    s = SubFigure(data=None, position=None, width=r'0.45\linewidth')

    s.add_image(filename='', width='r\linewidth', placement=None)

    s.add_caption(caption='')
    repr(s)

    # Matplotlib
    plot = Figure(data=None, position=None)

    x = [0, 1, 2, 3, 4, 5, 6]
    y = [15, 2, 7, 1, 5, 6, 9]

    pyplot.plot(x, y)

    plot.add_plot(width=r'0.8\textwidth', placement=r'\centering')
    plot.add_caption(caption='I am a caption.')
    repr(plot)

    # StandAloneGraphic
    stand_alone_graphic = StandAloneGraphic(
        filename='', image_options=r"width=0.8\textwidth")
    repr(stand_alone_graphic)
Exemplo n.º 3
0
def test_graphics():
    f = Figure(data=None, position=None)

    f.add_image(filename='', width=r'0.8\textwidth', placement=r'\centering')

    f.add_caption(caption='')

    # Subfigure
    s = SubFigure(data=None,
                  position=None,
                  width=r'0.45\linewidth',
                  seperate_paragraph=False)

    s.add_image(filename='', width='r\linewidth', placement=None)

    s.add_caption(caption='')

    # Matplotlib
    plot = MatplotlibFigure(data=None, position=None)

    x = [0, 1, 2, 3, 4, 5, 6]
    y = [15, 2, 7, 1, 5, 6, 9]

    pyplot.plot(x, y)

    plot.add_plot(width=r'0.8\textwidth', placement=r'\centering')
    plot.add_caption(caption='I am a caption.')

    # Quantities
    Quantity(quantity=1 * pq.kg)
    Quantity(quantity=1 * pq.kg, format_cb=lambda x: str(int(x)))
Exemplo n.º 4
0
def _append2latexdoc(doc, content):
    if isinstance(content, list):
        for item in content:
            if item.get('title'):
                doc.append(_get_section(**item))
                _append2latexdoc(doc, item['content'])
            else:
                _append2latexdoc(doc, item)
    else:
        section = _get_last_section(doc)
        if content.get('text'):
            if isinstance(content['text'], dict):
                section.append(open(content['text']['filename']).read())
            else:
                temp = ''
                if isinstance(content['text'],list):
                    for subtext in content['text']:
                        temp += subtext
                elif isinstance(content['text'],str):
                    temp = content['text']
                else:
                    raise Exception(f'Did not understand format of text string: \n {content["text"]}')
                section.append(temp)
        if content.get('latex_code'):
            if isinstance(content['latex_code'], dict):
                section.append(NoEscape(open(content['latex_code']['filename']).read()))
            else:
                section.append(NoEscape(content['latex_code']))
        if content.get('table'):
            for table in content['table']:
                section.append(NoEscape('\\begin{table}[H]'))  # note require float latex package for H command
                if table.get('filename'):
                    df = pd.read_excel(table['filename'], **table['kwargs'])
                elif isinstance(table.get('dataframe'),pd.DataFrame):
                    df = table.get('dataframe')
                section.append(NoEscape(df.to_latex(longtable=True,multicolumn_format='c')))
                section.append(NoEscape('\\end{table}'))
        if content.get('image'):
            for image in content.get('image'):
                section.append(NoEscape('\\begin{figure}[H]'))  # note require float latex package for H command
                Figure.add_image(section, image['filename'])
                section.append(NoEscape('\\end{figure}'))
        if content.get('subimage'):
            figure = Figure(position='H')
            for i, subimage in enumerate(content['subimage']):
                subfigure = SubFigure(width=NoEscape(
                    r'{}\linewidth'.format(np.round(1. / subimage.get('nr_horizontal_subimages', 2), 2) - 0.01)))
                subfigure.add_image(subimage['filename'])
                if subimage.get('caption', False):
                    subfigure.add_caption(subimage['caption'])
                if subimage.get('figure_caption', False) and i == 0:
                    figure.add_caption(subimage['figure_caption'])
                figure.append(subfigure)
                if (i + 1) % subimage.get('nr_horizontal_subimages', 2) == 0 and i != 0 or subimage.get(
                        'nr_horizontal_subimages', 2) == 1:
                    section.append(figure)
                    figure = Figure(arguments=NoEscape('\ContinuedFloat'), position='H')
            section.append(figure)
        if content.get('packages'):
            [doc.packages.append(Package(package)) for package in content['packages']]
Exemplo n.º 5
0
def test_graphics():
    f = Figure(data=None, position=None)

    f.add_image(filename="", width=r"0.8\textwidth", placement=r"\centering")

    f.add_caption(caption="")

    # Subfigure
    s = SubFigure(data=None, position=None, width=r"0.45\linewidth", seperate_paragraph=False)

    s.add_image(filename="", width="r\linewidth", placement=None)

    s.add_caption(caption="")

    # Matplotlib
    plot = MatplotlibFigure(data=None, position=None)

    x = [0, 1, 2, 3, 4, 5, 6]
    y = [15, 2, 7, 1, 5, 6, 9]

    pyplot.plot(x, y)

    plot.add_plot(width=r"0.8\textwidth", placement=r"\centering")
    plot.add_caption(caption="I am a caption.")

    # Quantities
    Quantity(quantity=1 * pq.kg)
    Quantity(quantity=1 * pq.kg, format_cb=lambda x: str(int(x)))
Exemplo n.º 6
0
def test_graphics():
    f = Figure(data=None, position=None)

    f.add_image(filename="", width=r"0.8\textwidth", placement=r"\centering")

    f.add_caption(caption="")

    # Subfigure
    s = SubFigure(data=None, position=None, width=r"0.45\linewidth", separate_paragraph=False)

    s.add_image(filename="", width="r\linewidth", placement=None)

    s.add_caption(caption="")

    # Matplotlib
    plot = Figure(data=None, position=None)

    x = [0, 1, 2, 3, 4, 5, 6]
    y = [15, 2, 7, 1, 5, 6, 9]

    pyplot.plot(x, y)

    plot.add_plot(width=r"0.8\textwidth", placement=r"\centering")
    plot.add_caption(caption="I am a caption.")
Exemplo n.º 7
0
 def createImage(self, filename, captionString):
     fig = SubFigure(position="h")
     file, typ = filename.split(".")
     fig.add_image("\"{}\".{}".format(file, typ), width="240px")
     fig.add_caption(captionString)
     return fig