예제 #1
0
def plot_main():
    fig, ax = gridplots(2, 2, r=0.8, ratio=1.3)
    # print("We get here?")
    functions = [np.sin, np.cos, np.tan, lambda x: 1 / np.tan(x)]
    func_names = ["sin", "cos", "tan", "cot"]

    x = np.linspace(-2.0, 2.0, 255) * np.pi

    for i, ax_ in enumerate(ax):
        y = functions[i](x)
        y[np.abs(y) > 10] = np.nan
        ax_.plot(x,
                 y,
                 "o",
                 markersize=2,
                 label="$y=\\{0}(x)$".format(func_names[i]))
        ax_.set_xlabel("$x$")
        ax_.set_ylabel("$y$")
        ax_.set_xticks(np.array([-2, -1, 0, 1, 2]) * np.pi)
        ax_.set_xticklabels([r"$-2\pi$", r"$-\pi$", "0", r"$\pi$", r"$2\pi$"])
        ax_.set_ylim(-2, 2)
        ax_.legend(
            loc=1,
            # prop=dict(size="large"),
            frameon=True)

    grid_labels(
        fig,
        ax,
        # offsets=[(0, 0), (0, 0),
        # (0, -0.03)]
    )

    fig.savefig(img_path / "example1.pgf")
예제 #2
0
def plot_main():
    fig, ax = gridplots(1, 2, r=0.8, ratio=2)
    # Left panel, use line plot
    ax_ = ax[0]
    ax_.plot(np.array([-2, -1, 0, 1, 2]), np.exp([1, 5, 10, 15, 20]))
    ax_.set_yscale("log")
    ax_.set_xlabel("$x$")
    ax_.set_ylabel("$y$")

    # Right panel, image plot
    ax_ = ax[1]
    xx, yy = np.meshgrid(
        np.linspace(-2, 2, 256) * np.pi,
        np.linspace(-2, 2, 256) * np.pi)
    zz = np.cos(np.sqrt(xx ** 2 + yy ** 2) \
                * np.sign( xx / (yy +
                                 np.finfo(np.float).eps)))  # very small num
    ax_.imshow(zz, extent=(xx.min(), xx.max(), yy.min(), yy.max()))
    ax_.set_xticks([])
    ax_.set_yticks([])

    grid_labels(fig, ax, offsets=[(0, 0), (0.04, 0)])
    # fig.set_constrained_layout(False)
    # ax[-1].set_axis_off()
    # fig.savefig(img_path / "example3.pgf")
    savepgf(fig, img_path / "example3.pgf", preview=False)
예제 #3
0
def plot_main():
    fig, ax = gridplots(
        1,
        2,
        r=0.8,
        # gridspec_kw=dict(width_ratios=(1.3, 0.7)),
        ratio=2)
    # fig.set_constrained_layout(False)
    # Left panel, use line plot

    ax_ = ax[0]
    add_img_ax(ax_, script_path.parent / "test/earth.jpg")

    ax_ = ax[1]
    xx, yy = np.meshgrid(
        np.linspace(-2, 2, 256) * np.pi,
        np.linspace(-2, 2, 256) * np.pi)
    zz = np.cos(np.sqrt(xx ** 2 + yy ** 2) \
                * np.sign( xx / (yy +
                                 np.finfo(np.float).eps)))  # very small num
    ax_.imshow(zz, extent=(xx.min(), xx.max(), yy.min(), yy.max()))
    # ax_.imshow(zz)
    ax_.set_xticks([])
    ax_.set_yticks([])

    labels = grid_labels(fig,
                         ax,
                         reserved_space=(0, 0),
                         offsets=[(0.02, -0.06), (0.03, -0.06)])
    labels[0].set_color("white")
    # ax[-1].set_axis_off()
    # fig.savefig(img_path / "example3.pgf")
    # fig.tight_layout()
    savepgf(fig, img_path / "example4.pgf")
예제 #4
0
def plot_main():
    fig, ax = gridplots(3, 3,
                        r=1,
                        span=[(0, 0, 1, 1), (0, 1, 1, 1), (0, 2, 1, 1),
                              (1, 0, 2, 3)],
                        ratio=1.5)
    functions = [np.sin, np.cos,
                 np.tan]
    func_names = ["sin", "cos", "tan"]

    x = np.linspace(-2.0, 2.0, 255) * np.pi
    
    for i, ax_ in enumerate(ax[: -1]):
        y = functions[i](x)
        y[np.abs(y) > 10] = np.nan
        ax_.plot(x, y, "o",
                 markersize=2,
                 label="$y=\\{0}(x)$".format(func_names[i]))
        ax_.set_xlabel("$x$")
        ax_.set_ylabel("$y$")
        ax_.set_xticks(np.array([-2, -1, 0, 1, 2]) * np.pi)
        ax_.set_xticklabels(["-2π", "-π", "0",
                              "π", "2π"])
        ax_.set_ylim(-2, 2)
        ax_.legend(loc=1, frameon=True)

    xx = np.linspace(0, 10, 256) * np.pi
    y1 = np.sin(xx)
    y2 = np.cos(xx)
    ax[-1].plot(xx, y1, "-", label="$\\sin(x)$")
    ax[-1].plot(xx, y2, "-", label="$\\cos(x)$")
    ax[-1].set_xticks(np.arange(0, 11) * np.pi)
    ax[-1].set_xticklabels(["0"] \
                           + ["${0}\\pi$".format(i) for i in range(1, 11)])
    ax[-1].set_xlabel("$x$")
    ax[-1].set_ylabel("$y$")
    ax[-1].set_yticks([-1, -0.5, 0, 0.5, 1])
    grid_labels(fig, ax,
                offsets=[(0, 0), (0, 0), (0, 0),
                         (0, -0.05)]
    )
    # fig.set_constrained_layout(False)
    # ax[-1].set_axis_off()
    fig.savefig(img_path / "example2.pgf")
예제 #5
0
def plot_main():
    fig, ax = gridplots(
        2,
        2,
        r=0.8,
        # gridspec_kw=dict(width_ratios=(1.3, 0.7)),
        ratio=1)
    # fig.set_constrained_layout(False)
    # Left panel, use line plot

    add_img_ax(ax[0], script_path.parent / "test/mercury.jpg")
    ax[0].text(x=0.5,
               y=0.98,
               s="Mercury",
               color="white",
               ha="center",
               va="top",
               transform=ax[0].transAxes)
    add_img_ax(ax[1], script_path.parent / "test/bluvenus.jpg")
    ax[1].text(x=0.5,
               y=0.98,
               s="Venus",
               color="white",
               ha="center",
               va="top",
               transform=ax[1].transAxes)
    add_img_ax(ax[2], script_path.parent / "test/earth.jpg")
    ax[2].text(x=0.5,
               y=0.98,
               s="Earth",
               color="white",
               ha="center",
               va="top",
               transform=ax[2].transAxes)
    add_img_ax(ax[3], script_path.parent / "test/mars.jpg")
    ax[3].text(x=0.5,
               y=0.98,
               s="Mars",
               color="white",
               ha="center",
               va="top",
               transform=ax[3].transAxes)

    labels = grid_labels(
        fig,
        ax,
        reserved_space=(0, 0),
    )
    # labels[0].set_color("white")
    # ax[-1].set_axis_off()
    # fig.savefig(img_path / "example3.pgf")
    # fig.tight_layout()
    savepgf(fig, img_path / "example5.pgf")
예제 #6
0
def plot_main():
    fig, ax = gridplots(1, 2, r=1, ratio=2.5)

    labels = ["aaa", "bbb", "ccc", "ddd", "eee", "fff"]
    xx = np.linspace(0, 1)
    for i, ax_ in enumerate(ax):
        for j, l in enumerate(labels):
            ax_.plot(xx,
                     np.ones_like(xx) * j,
                     "--",
                     label="$Sample: {0}$".format(l))
        ax_.set_xlabel("$x$")
        ax_.set_ylabel("$y$")

    ax[1].legend(loc="center left",
                 bbox_to_anchor=(1.05, 0.5),
                 fontsize="small")
    grid_labels(fig, ax, offsets=[(0, 0), (-0.1, 0)])
    # fig.set_constrained_layout(False)
    # ax[-1].set_axis_off()
    # mpl.use("pgf")
    fig.savefig(img_path / "example2a.pdf")
    fig.savefig(img_path / "example2a.pgf")