Ejemplo 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='')

    # 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)))
Ejemplo n.º 2
0
def test_quantities():
    # Quantities
    Quantity(quantity=1 * pq.kg)
    q = Quantity(quantity=1 * pq.kg, format_cb=lambda x: str(int(x)))
    repr(q)
Ejemplo n.º 3
0
from pylatex import Document, Section, Subsection, Math, Quantity

if __name__ == '__main__':
    doc = Document()
    section = Section('Quantity tests')

    subsection = Subsection('Scalars with units')
    G = pq.constants.Newtonian_constant_of_gravitation
    moon_earth_distance = 384400 * pq.km
    moon_mass = 7.34767309e22 * pq.kg
    earth_mass = 5.972e24 * pq.kg
    moon_earth_force = G * moon_mass * earth_mass / moon_earth_distance**2
    q1 = Quantity(moon_earth_force.rescale(pq.newton),
                  options={
                      'round-precision': 4,
                      'round-mode': 'figures'
                  })
    math = Math(data=['F=', q1])
    subsection.append(math)
    section.append(subsection)

    subsection = Subsection('Scalars without units')
    world_population = 7400219037
    N = Quantity(world_population,
                 options={
                     'round-precision': 2,
                     'round-mode': 'figures'
                 },
                 format_cb="{0:23.17e}".format)
    subsection.append(Math(data=['N=', N]))
Ejemplo n.º 4
0
#!/usr/bin/python
"""
This example shows quantities functionality.

..  :copyright: (c) 2014 by Jelte Fennema.
    :license: MIT, see License for more details.
"""

# begin-doc-include
import quantities as pq

from pylatex import Document, Section, Subsection, Math, Quantity

if __name__ == '__main__':
    doc = Document()
    section = Section('Quantity tests')
    subsection = Subsection('Scalars')

    G = pq.constants.Newtonian_constant_of_gravitation
    moon_earth_distance = 384400 * pq.km
    moon_mass = 7.34767309e22 * pq.kg
    earth_mass = 5.972e24 * pq.kg
    moon_earth_force = G * moon_mass * earth_mass / moon_earth_distance**2
    q1 = Quantity(moon_earth_force.rescale(pq.newton))
    math = Math(data=['F=', q1])
    subsection.append(math)
    section.append(subsection)
    doc.append(section)
    doc.generate_pdf('quantities_ex')