<reponame>iwamura-lab/my_codes
#!/usr/bin/env python

import argparse

import matplotlib.pyplot as plt
import numpy as np

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("file_names", nargs="*", help="data file names")
    parser.add_argument(
        "--xlim",
        nargs=3,
        type=int,
        default=None,
        help="X axis limits. start, stop, step.",
    )
    parser.add_argument("--ylim", nargs=2, default=["0", "0"], help="Y axis limits")
    parser.add_argument("--xlabel", default="Training data size", help="X axis label")
    parser.add_argument("--ylabel", default="prediction_error", help="Y axis label")
    parser.add_argument(
        "--ticksize", type=int, default=15, help="X axis or Y axis tick size"
    )
    parser.add_argument("-p", "--plot", action="store_true", help="plot mode")
    parser.add_argument(
        "-f", "--figure", default="datasize_dependence.png", help="graph name"
    )
    args = parser.parse_args()

    # plt.rcParams['text.usetex'] = True
    plt.rcParams["font.size"] = 18
    plt.rcParams["font.family"] = "Times New Roman"

    x_array = []
    y_array = []
    colors = ["#ff7f0e", "#2ca02c", "#d62728"]
    for filename in args.file_names:
        with open(filename) as f:
            data = [line.split() for line in f]
        x = np.array([int(i[0]) for i in data])
        y = np.array([float(i[1]) for i in data])
        x_array.append(x)
        y_array.append(y)

    fig, ax = plt.subplots()
    fig.set_tight_layout(True)
    fig.patch.set_alpha(0)
    for x, y, color in zip(x_array, y_array, colors):
        ax.plot(x, y, c=color)
        ax.scatter(x, y, c=color)

    if args.xlim is not None:
        ax.set_xlim(args.xlim[0], args.xlim[1])
        xticks = [tick for tick in range(args.xlim[0], args.xlim[1] + 1, args.xlim[2])]
        ax.set_xticks(xticks)
        ax.set_xticklabels(xticks)
    if args.ylim != ["0", "0"]:
        if all([lim.isdigit() for lim in args.ylim]):
            ylim = tuple(map(int, args.ylim))
            ax.set(
                xlim=(0, 5000),
                ylim=ylim,
                xlabel="training data size",
                ylabel=args.ylabel,
            )
        else:
            ylim = tuple(map(float, args.ylim))
            ax.set(
                xlim=(0, 5000),
                ylim=ylim,
                xlabel="training data size",
                ylabel=args.ylabel,
            )
    if args.plot:
        plt.show()
    else:
        plt.savefig(args.figure)

#!/usr/bin/env python

import argparse

import matplotlib.pyplot as plt
import numpy as np

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("file_names", nargs="*", help="data file names")
    parser.add_argument(
        "--xlim",
        nargs=3,
        type=int,
        default=None,
        help="X axis limits. start, stop, step.",
    )
    parser.add_argument("--ylim", nargs=2, default=["0", "0"], help="Y axis limits")
    parser.add_argument("--xlabel", default="Training data size", help="X axis label")
    parser.add_argument("--ylabel", default="prediction_error", help="Y axis label")
    parser.add_argument(
        "--ticksize", type=int, default=15, help="X axis or Y axis tick size"
    )
    parser.add_argument("-p", "--plot", action="store_true", help="plot mode")
    parser.add_argument(
        "-f", "--figure", default="datasize_dependence.png", help="graph name"
    )
    args = parser.parse_args()

    # plt.rcParams['text.usetex'] = True
    plt.rcParams["font.size"] = 18
    plt.rcParams["font.family"] = "Times New Roman"

    x_array = []
    y_array = []
    colors = ["#ff7f0e", "#2ca02c", "#d62728"]
    for filename in args.file_names:
        with open(filename) as f:
            data = [line.split() for line in f]
        x = np.array([int(i[0]) for i in data])
        y = np.array([float(i[1]) for i in data])
        x_array.append(x)
        y_array.append(y)

    fig, ax = plt.subplots()
    fig.set_tight_layout(True)
    fig.patch.set_alpha(0)
    for x, y, color in zip(x_array, y_array, colors):
        ax.plot(x, y, c=color)
        ax.scatter(x, y, c=color)

    if args.xlim is not None:
        ax.set_xlim(args.xlim[0], args.xlim[1])
        xticks = [tick for tick in range(args.xlim[0], args.xlim[1] + 1, args.xlim[2])]
        ax.set_xticks(xticks)
        ax.set_xticklabels(xticks)
    if args.ylim != ["0", "0"]:
        if all([lim.isdigit() for lim in args.ylim]):
            ylim = tuple(map(int, args.ylim))
            ax.set(
                xlim=(0, 5000),
                ylim=ylim,
                xlabel="training data size",
                ylabel=args.ylabel,
            )
        else:
            ylim = tuple(map(float, args.ylim))
            ax.set(
                xlim=(0, 5000),
                ylim=ylim,
                xlabel="training data size",
                ylabel=args.ylabel,
            )
    if args.plot:
        plt.show()
    else:
        plt.savefig(args.figure)
#!/usr/bin/env python # plt.rcParams['text.usetex'] = True