コード例 #1
0
def test_pyplot(setup):
    import scipy.misc
    import matplotlib
    matplotlib.use('TKAgg')
    import matplotlib.pyplot as plt
    import numpy as np

    face = scipy.misc.face()
    logger.log_image(face, "face.png")

    fig = plt.figure(figsize=(4, 2))
    xs = np.linspace(0, 5, 1000)
    plt.plot(xs, np.cos(xs))
    logger.savefig("face_02.png", fig=fig)
    plt.close()

    fig = plt.figure(figsize=(4, 2))
    xs = np.linspace(0, 5, 1000)
    plt.plot(xs, np.cos(xs))
    logger.savefig('sine.pdf')
コード例 #2
0
def plot_trajectory_rope(path,
                         ds,
                         all_images,
                         n_cols=8,
                         title=None,
                         key="figures/rope_play.png"):
    from math import ceil
    from matplotlib.gridspec import GridSpec
    from ml_logger import logger

    stack = all_images[path][:, 0]
    n, h, w, *c = stack.shape
    n_rows = ceil(n / n_cols)
    # todo: add color background -- need to decide on which library to use.
    fig = plt.figure(figsize=np.array(1.4, dtype=int) * [n_cols, n_rows])

    if title:
        plt.suptitle(title, fontsize=14)
    gs = GridSpec(n_rows, 10)
    index = 0
    for _row in range(n_rows):
        for _col in range(10):
            if index == len(stack):
                break
            plt.subplot(gs[_row, _col])
            plt.imshow(stack[index], cmap='gray')
            plt.text(0, 10, f"#{path[index]}", fontsize=8)
            if index > 0:
                plt.text(0, 60, f"{ds[index - 1]:0.2f}", fontsize=8)
            plt.axis('off')
            index += 1

    plt.tight_layout()
    logger.savefig(key=key)
    plt.show()
    return
コード例 #3
0
        short_name = short_names[key]

        path, ds = search(G, start, goal, partial(heuristic, G=G, scale=Args.h_scale))
        cache.cost[short_name] = len(queries.keys())
        cache.len[short_name] = sum(ds)
        print(f"{key:>10} len: {len(path)}", f"cost: {len(queries.keys())}")
        plt.subplot(2, 2, i + 1)
        plt.title(title, pad=10)
        # plot_graph(G)
        plot_trajectory_2d(ind2pos(G, path, 100), label=short_name)
        plt.scatter(*zip(*ind2pos(G, queries.keys(), 100)), color="gray", s=3, alpha=0.6)
        set_fig()

    # plt.legend(loc="upper left", bbox_to_anchor=(0.45, 0.8), framealpha=1, frameon=False, fontsize=12)
    plt.tight_layout()
    logger.savefig("../figures/maze_plans.png", dpi=300)
    plt.show()
    plt.close()

    # colors = ['#49b8ff', '#ff7575', '#66c56c', '#f4b247']
    fig = plt.figure(figsize=(3.8, 3), dpi=300)
    plt.title('Planning Cost')
    plt.bar(cache.cost.keys(), cache.cost.values(), color="gray", width=0.8)
    plt.ylim(0, max(cache.cost.values()) * 1.2)
    plt.gca().spines['top'].set_visible(False)
    plt.gca().spines['right'].set_visible(False)
    plt.tight_layout()
    logger.savefig("../figures/maze_cost.png", dpi=300)
    plt.ylabel('# of distance lookup')
    plt.show()
コード例 #4
0
    plot_trajectory_2d(path, label="heuristics")

    G = nx.grid_graph(dim=[5, 5])
    G.add_edge((0, 0), (0, 1), weight=1)
    for e in G.edges(data=True):
        e[-1]['weight'] = 1
    path = dijkstra(G, (0, 0), (4, 4))
    print("  dijkstra", *path)

    plt.subplot(2, 2, 3)
    plt.title('Dijkstra')
    plot_trajectory_2d(path, label="dijkstra")

    path = a_star(G, (0, 0), (4, 4))
    print("        a*", *path)

    plt.subplot(2, 2, 4)
    plt.title('A*')
    plot_trajectory_2d(path, label="A*")

    plt.legend(loc="upper left",
               bbox_to_anchor=(0.45, 0.8),
               framealpha=1,
               frameon=False,
               fontsize=12)
    from ml_logger import logger

    plt.tight_layout()
    logger.savefig("../figures/comparison.png", dpi=300)
    plt.show()
コード例 #5
0
        cache.cost[short_name] = len(queries.keys())
        cache.len[short_name] = len(ds)
        print(f"{key:>10} len: {len(path)}", f"cost: {len(queries.keys())}")
        plt.subplot(2, 2, i + 1)
        plt.title(title, pad=10)
        # plot_graph(G)
        plot_trajectory_2d(ind2pos(G, path, 100), label=short_name)
        plt.scatter(*zip(*ind2pos(G, queries.keys(), 100)),
                    color="gray",
                    s=3,
                    alpha=0.1)
        set_fig(dataset)

    # plt.legend(loc="upper left", bbox_to_anchor=(0.45, 0.8), framealpha=1, frameon=False, fontsize=12)
    plt.tight_layout()
    logger.savefig("../figures/streetlearn_plans.png", dpi=300)
    plt.show()
    plt.close()

    # colors = ['#49b8ff', '#ff7575', '#66c56c', '#f4b247']
    # for i, (k, v) in enumerate(cache.items()):
    #     plt.bar(k, v, color=colors[i])

    fig = plt.figure(figsize=(3.8, 3), dpi=300)
    plt.title('Planning Cost')
    plt.bar(cache.cost.keys(), cache.cost.values(), color="gray", width=0.8)
    plt.ylim(0, max(cache.cost.values()) * 1.2)
    plt.gca().spines['top'].set_visible(False)
    plt.gca().spines['right'].set_visible(False)
    plt.tight_layout()
    logger.savefig("../figures/streetlearn_cost.png", dpi=300)
コード例 #6
0
ファイル: __init__.py プロジェクト: geyang/graph-search
    print("  dijkstra", *path)
    plt.subplot(2, 2, 3)
    plt.title('Dijkstra')
    plot_trajectory_2d(path, label="dijkstra")
    plt.scatter(*zip(*queries.keys()),
                color="#23aaff",
                linewidths=0,
                alpha=0.6)

    queries.clear()
    path, ds = a_star(G, start, goal, heuristic)
    print("        a*", *path)
    plt.subplot(2, 2, 4)
    plt.title('A*')
    plot_trajectory_2d(path, label="A*")
    plt.scatter(*zip(*queries.keys()),
                color="#23aaff",
                linewidths=0,
                alpha=0.6)

    plt.legend(loc="upper left",
               bbox_to_anchor=(0.45, 0.8),
               framealpha=1,
               frameon=False,
               fontsize=12)
    from ml_logger import logger

    plt.tight_layout()
    logger.savefig("../figures/search_range.png", dpi=300)
    plt.show()
コード例 #7
0
                         all_images,
                         title="A*",
                         key=f"../figures/rope_plans/bfs.png")

    # colors = ['#49b8ff', '#ff7575', '#66c56c', '#f4b247']
    # for i, (k, v) in enumerate(cache.items()):
    #     plt.bar(k, v, color=colors[i])

    fig = plt.figure(figsize=(3.8, 3), dpi=300)
    plt.title('Planning Cost')
    plt.bar(cache.cost.keys(), cache.cost.values(), color="gray", width=0.8)
    plt.ylim(0, max(cache.cost.values()) * 1.2)
    plt.gca().spines['top'].set_visible(False)
    plt.gca().spines['right'].set_visible(False)
    plt.tight_layout()
    logger.savefig("../figures/rope_cost.png", dpi=300)
    plt.ylabel('# of distance lookup')
    plt.show()

    fig = plt.figure(figsize=(3.8, 3), dpi=300)
    plt.title('Plan Length')
    plt.bar(cache.len.keys(), cache.len.values(), color="gray", width=0.8)
    plt.ylim(0, max(cache.len.values()) * 1.2)
    plt.gca().spines['top'].set_visible(False)
    plt.gca().spines['right'].set_visible(False)
    plt.tight_layout()
    logger.savefig("../figures/rope_length.png", dpi=300)
    plt.ylabel('# of Steps')
    plt.show()

    logger.print('done', color="green")