コード例 #1
0
    def test_save(self):

        x = np.linspace(0, 1, 100)
        y = np.sin(x)

        plt.plot(x, y)

        # Test matplotlib
        viz.save("test.pdf")
        self.assertTrue(os.path.exists("test.pdf"))
        os.remove("test.pdf")

        # Test tikzplotlib
        viz.save("test.tikz", include_disclaimer=False)
        self.assertTrue(os.path.exists("test.tikz"))

        # We save the file size so that we can compare it to the "cleaned"
        # version
        file_size_og = os.stat("test.tikz").st_size

        os.remove("test.tikz")

        # Test with clean figure
        viz.save(
            "test.tikz",
            tikz_clean_figure=True,
            target_resolution=200,
            include_disclaimer=False,
        )
        self.assertTrue(os.path.exists("test.tikz"))
        # The cleaned file should be smaller
        file_size_cleaned = os.stat("test.tikz").st_size
        self.assertLess(file_size_cleaned, file_size_og)
        os.remove("test.tikz")
コード例 #2
0
            # Try to draw the shape of the horizon
            if args.draw_horizons and time in horizons[ah].shape_times:

                cut = {
                    "xy": (None, None, 0),
                    "xz": (None, 0, None),
                    "yz": (0, None, None),
                }

                logger.debug(f"Drawing shape at time {time} for ah {ah}")
                shape = horizons[ah].shape_outline_at_time(
                    time, cut[args.type])
                ax.fill(shape[0], shape[1])
            else:
                logger.debug(f"Shape not available at {time} for ah {ah}")

        ax.set_xlabel(to_plot_x)
        ax.set_ylabel(to_plot_y)

        ax.set_aspect("equal")

    ax.legend()
    time = x_coord[ah].tmax
    add_text_to_figure_corner(fr"$t = {time:.3f}$")

    output_path = os.path.join(args.outdir, figname)
    logger.debug(f"Saving in {output_path}")
    plt.tight_layout()
    save(output_path, args.fig_extension, as_tikz=args.as_tikz)