Example #1
0
def demo1():
    x1 = np.linspace(0.0, 5.0)
    x2 = np.linspace(0.0, 2.0)

    y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
    y2 = np.cos(2 * np.pi * x2)

    plt.subplot(2, 1, 1)
    plt.plot(x1, y1, 'o-')
    plt.title('A tale of 2 subplots')
    plt.ylabel('Damped oscillation')

    plt.subplot(2, 1, 2)
    plt.plot(x2, y2, '.-')
    plt.xlabel('time (s)')
    plt.ylabel('Undamped')

    # Make a document and put a plot in it

    doc = tydoc()
    doc.h1("Matplotlib demo")
    doc.p(["This demonstrates how you can add ",b("matplotlib"),
           " to your documents"])
    doc.append_matplotlib(plt,dpi=72,pad_inches=0.1)
    doc.p("Pretty neat, eh?")
    doc.save("demo1.html")
    doc.save("demo1.tex")
    doc.save("demo1.md")
    
    # Just for grins, let's also run LaTeX
    latex_tools.run_latex("demo1.tex", delete_tempfiles=True)
Example #2
0
def demo2():
    doc = tydoc()
    doc.h1("sin(x) graph")
    doc.p("Here is a little graph of sin(x) from 0 to 4π")
    doc.p("A second paragraph")
    x = np.linspace(0, np.pi*4)
    fig = Figure(figsize=(4,2))
    FigureCanvasAgg(fig)
    ax = fig.add_subplot(111)
    ax.plot(x, np.sin(x))
    doc.append_matplotlib(fig, dpi=72, pad_inches=0.1)
    doc.p("A third paragraph")

    doc.h1("sin(2x) graph")
    doc.p("Here is a little graph of sin(2x) from 0 to π")
    x = np.linspace(0, np.pi)
    fig = Figure(figsize=(4,2))
    FigureCanvasAgg(fig)
    ax = fig.add_subplot(111)
    ax.plot(x, np.sin(2*x))
    doc.append_matplotlib(fig, dpi=72, pad_inches=0.1)
    doc.save("demo2.html")
    doc.save("demo2.tex")
    doc.save("demo2.md")
    # Just for grins, let's also run LaTeX
    latex_tools.run_latex("demo2.tex", delete_tempfiles=True)
Example #3
0
 def typeset(self, pdf_name):
     """Typeset the template"""
     tt_bom = make_bom()
     tt_bom.latex_colspec = "lllrrl"
     tt_run = make_runtime()
     self.params['%%ADDITION%%'] = tt_bom.typeset(
         mode='latex') + tt_run.typeset(mode='latex')
     with open(self.template) as f:
         data = f.read()
         for (k, v) in self.params.items():
             data = data.replace(k, v)
         outdir = tempfile.mkdtemp()
         out = tempfile.NamedTemporaryFile(encoding="utf-8",
                                           suffix=".tex",
                                           mode="w+t",
                                           dir=outdir,
                                           delete=False)
         out.write(data)
         out.flush()
         # Save a copy for testing
         # open("test.tex","w").write(data)
         shutil.copy(self.seal, os.path.dirname(out.name))
         shutil.copy(self.background, os.path.dirname(out.name))
         run_latex(out.name, delete_tempfiles=False, repeat=2)
         shutil.move(out.name.replace(".tex", ".pdf"), pdf_name)
         shutil.rmtree(outdir)
Example #4
0
def test_analyze_xlsx():
    """ This just test to make sure that the LaTeX file created can be processed."""
    assert SPREADSHEET_TEX != SPREADSHEET_TXT

    rm_Rf(WORK2_DIR)
    os.mkdir(WORK2_DIR)
    shutil.copy(XLSX_PATH, WORK2_DIR)
    print("==>", SPREADSHEET_TEX, SPREADSHEET_TXT)
    with open(SPREADSHEET_TEX, "w") as f:
        f.write("\\documentclass{article}\\begin{document}\n")
        f.write(analyze_xlsx(filename=SPREADSHEET_XLSX, mode=LATEX))
        f.write("\\end{document}\n")
    with open(SPREADSHEET_TXT, "w") as f:
        f.write(analyze_xlsx(filename=SPREADSHEET_XLSX, mode=TEXT))

    run_latex(SPREADSHEET_TEX, repeat=1)