"""Literal Python conversion of fig3_1.m."""

import numpy as np
import matplotlib.pyplot as plt
from cycler import cycler


def fig3_1():
    # matlab versus 2*n^3/3 for LU

    ### Values obtained using file cores.m

    # first edition
    # n_single = [100   200   400   800   1600   3200   6400   9900]
    # t_single = [77.7066e-6   281.4723e-6     1.5626e-3    10.2545e-3    86.4495e-3   658.1376e-3     3.7922    12.8114]

    # second edition: iMac Pro
    n = np.array([100, 500, 1000, 2000, 4000, 8000, 16000, 32000])
    t_single = np.array([4.71e-05, 2.20e-03, 1.43e-02, 1.34e-01,
                         8.61e-01, 4.27e+00, 3.09e+01, 2.32e+02])
    t_10 = np.array([4.94e-05, 1.46e-03, 7.34e-03, 2.39e-02,
                     1.54e-01, 9.35e-01, 7.04e+00, 4.78e+01])

    plt.close("all")
    # get(gcf)
    # MATLAB Position [25 1115 658 230], scaled to fit the plot window.
    fig, ax = plt.subplots(figsize=(8.6, 3.2))
    # subaxis(1,1,1,1,'MT',0.01,'MB',0.2,'MR',-0.015,'ML',0.08,'P',0.04)
    fig.subplots_adjust(top=0.97, bottom=0.24, right=0.98, left=0.11)
    co = np.array([
        [0, 0, 1],
        [0, 0.5, 0],
        [1, 0, 0],
        [0, 0.75, 0.75],
        [0.75, 0, 0.75],
        [0.75, 0.75, 0],
        [0.25, 0.25, 0.25],
    ])
    ax.set_prop_cycle(cycler(color=co.tolist()))

    ax.loglog(n, t_10, "--ob", markersize=9, linewidth=1.4)
    ax.loglog(n, t_single, "-*r", markersize=9, linewidth=1.4)
    ax.set_frame_on(True)
    ax.grid(True)
    ax.axis([1e2, 1e5, 1e-5, 1e3])
    ax.set_yticks([1e-5, 1e-3, 1e-1, 1e1, 1e3])
    ax.set_xlabel("n-axis", fontsize=12, fontweight="bold")
    ax.set_ylabel("Time (sec)", fontsize=12, fontweight="bold")

    #  get(legend)
    ax.legend([" 10 Cores", " 1 Core"], loc="lower right", fontsize=12)

    ax.tick_params(labelsize=12)
    for label in ax.get_xticklabels() + ax.get_yticklabels():
        label.set_fontweight("bold")

    plt.show()
    return fig, ax

    # fig.savefig('/Users/mark/Desktop/time.eps')


if __name__ == "__main__":
    fig3_1()
