示例#1
0
    def test_add_plot(self):
        fig = Figure()
        name = "test"
        plt.figure()
        plt.plot(x, y)
        fig.add_plot(name)

        # check if correct latex output is produced
        self.assertEqual(
            fig.dumps(),
            ("\\begin{figure}%\n\\centering%\n\\includegraphics[width=0.8" +
             "\\textwidth]{Graphs/test.jpg}%\n\\end{figure}"),
        )
        plt.close()
示例#2
0
    def test_reset(self):
        fig = Figure()
        # figure 1
        for i in range(1, 3):
            name = f"test{i}"
            plt.figure()
            plt.plot(x, y, label=i)
            fig.add_plot(name)

            # check if correct latex output is produced
            self.assertEqual(
                fig.dumps(),
                (f"\\begin{{figure}}%\n\\centering%\n\\includegraphics[width=0.8\\textwidth]"
                 + f"{{Graphs/test{i}.jpg}}%\n\\end{{figure}}"),
            )
            fig.reset(show=False, close=True)
示例#3
0
    def test_two(self):
        doc = Document()
        fig = Figure()
        with doc.create(Figure()) as fig:
            with fig.create(
                    SubFigure(width=NoEscape(r"0.48\textwidth"))) as left:
                name = "left"
                plt.figure()
                plt.plot(x, y, label="l")
                plt.legend()
                left.add_plot(name, caption=name)
                plt.close()

            with fig.create(
                    SubFigure(width=NoEscape(r"0.48\textwidth"))) as right:
                name = "right"
                plt.figure()
                plt.plot(x, y, label="r")
                plt.legend()
                right.add_plot(name, caption=name)
                plt.close()

            fig.add_caption_label("full", "full", above=False)

            self.assertEqual(
                fig.dumps(),
                ("\\begin{figure}%\n\\begin{subfigure}{0.48\\textwidth}%" +
                 "\n\\caption{left}%\n\\zlabel{fig:left}%\n\\includegraphics[width=\\linewidth]"
                 +
                 "{Graphs/left.jpg}%\n\\end{subfigure}%\n\\begin{subfigure}{0.48\\textwidth}%"
                 +
                 "\n\\caption{right}%\n\\zlabel{fig:right}%\n\\includegraphics[width="
                 +
                 "\\linewidth]{Graphs/right.jpg}%\n\\end{subfigure}%\n\\caption{full}%\n"
                 + "\\zlabel{fig:full}%\n\\end{figure}"),
            )
        doc.generate_tex("Latex/twosubfigures")