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_8() -> None:
    # this also has fig10_9

    nt = 1000
    t = np.linspace(0, 10, nt)
    w1 = np.pi
    w2 = 2 * np.pi
    w3 = 0.1 * np.pi
    del w3
    S1 = np.zeros(nt)
    S2 = np.zeros(nt)
    for it in range(nt):
        S1[it] = np.sin(w1 * t[it])
        # S2[it] = 2*np.sin(w2*t[it]-1)-4*np.exp(-0.1*t[it])*np.sin(t[it])
        S2[it] = (1 / 5) * (2.5 * np.sin(w2 * t[it] - 1) + 0.3 * t[it] * (10 - t[it]))

    M11 = 1; M12 = 2
    M21 = 2; M22 = -2

    set_color_order()
    fig1 = matlab_figure([7, 1028, 599, 317], num=1)
    ax = subaxis(2, 1, 1, 1, "MT", 0.04, "MB", 0.13, "MR", 0.001, "ML", 0.055, "P", 0.03)
    assert ax is not None
    ax.plot(t, S1, linewidth=1.4)
    ax.set_ylabel(r"$s_1$ -axis", fontsize=12, fontweight="bold")
    ax.grid(True)
    ax.set_frame_on(True)
    set_axes_font(ax, 12, "bold")

    ax = subaxis(2, 1, 1, 2)
    assert ax is not None
    ax.plot(t, S2, "r", linewidth=1.4)
    ax.set_xlabel("t-axis")
    ax.set_ylabel(r"$s_2$ -axis")
    ax.grid(True)
    ax.set_frame_on(True)
    set_axes_font(ax, 12, "bold")

    # fig1.savefig('/Users/holmes/Desktop/wave1.eps')

    x1 = M11 * S1 + M12 * S2                  # mixing 1
    x2 = M21 * S1 + M22 * S2                  # mixing 2

    fig2 = matlab_figure([610, 1029, 598, 316], num=2)
    ax = subaxis(2, 1, 1, 1, "MT", 0.04, "MB", 0.13, "MR", 0.001, "ML", 0.053, "P", 0.03)
    assert ax is not None
    ax.plot(t, x1, linewidth=1.4)              # plot mixing 1
    ax.set_ylabel(r"$x_1$ -axis")
    ax.axis([0, 10, -1, 5])
    ax.grid(True)
    ax.set_frame_on(True)
    set_axes_font(ax, 12, "bold")

    ax = subaxis(2, 1, 1, 2)
    assert ax is not None
    ax.plot(t, x2, "r", linewidth=1.4)        # plot mixing 2
    ax.set_xlabel("t-axis")
    ax.set_ylabel(r"$x_2$ -axis")
    ax.axis([0, 10, -6, 1.5])
    ax.set_yticks([-6, -3, 0])
    ax.grid(True)
    ax.set_frame_on(True)
    set_axes_font(ax, 12, "bold")

    # fig2.savefig('/Users/holmes/Desktop/wave2.eps')
    finish_figure(fig1)
    finish_figure(fig2)
    plt.show()


if __name__ == "__main__":
    fig10_8()
