"""Literal Python conversion of fig3_5.m."""

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


def fig3_5():
    a1 = 1
    b1 = 2
    a2 = 2
    b2 = 1

    nt = 200
    th = np.linspace(0, 2 * np.pi, nt)

    x1 = np.zeros(nt)
    y1 = np.zeros(nt)
    x2 = np.zeros(nt)
    y2 = np.zeros(nt)
    for it in range(nt):
        x1[it] = np.cos(th[it]) / a1
        y1[it] = np.sin(th[it]) / b1
        x2[it] = np.cos(th[it]) / a2
        y2[it] = np.sin(th[it]) / b2

    plt.close("all")
    # get(gcf)
    # MATLAB Position [14 1014 386 331], scaled to fit the plot window.
    fig, ax = plt.subplots(figsize=(5.0, 4.3), constrained_layout=True)
    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.plot(x1, y1, "--r", linewidth=2)
    ax.plot(x2, y2, "b", linewidth=1.6)
    ax.set_aspect("equal", adjustable="box")
    ax.axis([-1.1, 1.1, -1.1, 1.1])
    ax.set_frame_on(True)
    ax.grid(True)
    ax.set_xlabel("x-axis", fontsize=16, fontweight="bold")
    ax.set_ylabel("y-axis", fontsize=16, fontweight="bold")
    ax.tick_params(labelsize=16)
    for label in ax.get_xticklabels() + ax.get_yticklabels():
        label.set_fontweight("bold")

    plt.show()
    return fig, ax


if __name__ == "__main__":
    fig3_5()
