from __future__ import annotations

import matplotlib.pyplot as plt
import numpy as np

from plot_helpers import finish_figure, matlab_figure, set_axes_font, set_color_order
from subaxis import subaxis


def fig10_7() -> None:
    #%% this requires the subaxis and parseArgs files

    s = np.zeros(8)
    s[0] = 4.220; s[1] = 1.2228; s[2] = 0.9237; s[3] = 0.8631
    s[4] = 0.3446; s[5] = 0.2308; s[6] = 0.1186; s[7] = 0.0413

    s[0] = 18.8063; s[1] = 5.4178; s[2] = 4.2784; s[3] = 3.1603; s[4] = 1.6044; s[5] = 1.2829; s[6] = 0.6506; s[7] = 0.1837

    j = np.zeros(8)
    E = np.zeros(8)
    for i in range(7):
        j[i] = i + 1
        E[i] = np.linalg.norm(s[i + 1 : 8], 2) ** 2 / np.linalg.norm(s, 2) ** 2
    j[7] = 8
    E[7] = 0

    avg = np.linalg.norm(s, 1) / 8
    print(avg)

    print(E)

    set_color_order()
    fig = matlab_figure([25, 930, 660, 420])

    ax = subaxis(2, 1, 1, "MT", 0.02, "MB", 0.1, "MR", -0.03, "ML", 0.04, "P", 0.05)
    assert ax is not None
    ax.plot(j, s, "o--", linewidth=2, markersize=9)
    ax.set_ylabel("Sigma")
    ax.grid(True)
    ax.set_frame_on(True)
    set_axes_font(ax, 14, "bold")

    ax = subaxis(2, 1, 2)
    assert ax is not None
    ax.plot(j, E, "o--", linewidth=2, markersize=9)
    ax.set_xlabel("k-axis")
    ax.set_ylabel("Error")
    ax.grid(True)
    ax.set_frame_on(True)
    set_axes_font(ax, 14, "bold")

    # fig.savefig('/Users/holmes/Desktop/pcaE.eps')
    finish_figure(fig)
    plt.show()


if __name__ == "__main__":
    fig10_7()
