"""Literal Python conversion of fig8_11.m."""

import matplotlib.pyplot as plt
import numpy as np


def fig8_11():
    #  generate data for regression
    nd = 50
    rdd = 0.7 * (0.5 - np.random.rand(nd))
    thetad = 2 * np.pi * np.random.rand(nd)
    xd = np.zeros(nd)
    yd = np.zeros(nd)
    for i in range(nd):
        xd[i] = (3 + rdd[i]) * np.cos(thetad[i])
        yd[i] = (3 + rdd[i]) * np.sin(thetad[i])

    r = np.linalg.norm(3 + rdd, 1) / nd
    #  evaluate interpolation fn's for use in plotting
    #  N = number of points plotted
    n = 300
    theta = np.linspace(0, 2 * np.pi, n)
    x = np.zeros(n)
    y = np.zeros(n)
    for ix in range(n):
        x[ix] = r * np.cos(theta[ix])
        y[ix] = r * np.sin(theta[ix])

    plt.close("all")
    # get(gcf)
    # MATLAB Position [23 974 430 371], scaled to fit the plot window.
    fig, ax = plt.subplots(figsize=(4.3, 4.0), layout="constrained")
    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(color=co)

    ax.plot(x, y, "r", linewidth=1.6)
    ax.plot(xd, yd, ".b", markersize=22)
    ax.axis([-4, 4, -4, 4])
    ax.set_yticks([-4, -2, 0, 2, 4])
    ax.grid(True)
    ax.set_frame_on(True)
    ax.set_xlabel("x-axis", fontsize=14, fontweight="bold")
    ax.set_ylabel("y-axis", fontsize=14, fontweight="bold")
    ax.set_aspect("equal", adjustable="box")
    ax.tick_params(labelsize=14)
    for label in ax.get_xticklabels() + ax.get_yticklabels():
        label.set_fontweight("bold")

    # fig.savefig('/Users/mark/Desktop/circle.eps')
    plt.show()


if __name__ == "__main__":
    fig8_11()
