"""Literal Python conversion of fig8_4.m."""

import matplotlib.pyplot as plt
import numpy as np


def fig8_4():
    plt.close("all")
    # get(gcf)
    # MATLAB Position [25 1115 658 230], scaled to fit the plot window.
    fig, ax = plt.subplots(figsize=(6.58, 3.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)

    #  data
    xd = np.zeros(4)
    yd = np.zeros(4)
    xd[0] = -1; xd[1] = 2; xd[2] = 0; xd[3] = 1
    yd[0] = 1; yd[1] = -1; yd[2] = 2; yd[3] = 1

    # regression line
    v1 = 11 / 10; v2 = -7 / 10
    x1 = -1; y1 = v1 + v2 * x1
    x4 = 2; y4 = v1 + v2 * x4

    ax.plot(xd, yd, ".b", markersize=30)
    ax.plot([x1, x4], [y1, y4], "r", linewidth=1.6)
    ax.axis([-1.1, 2.1, -1.2, 2.2])
    ax.grid(True)
    ax.set_xlabel("x-axis", fontsize=14, fontweight="bold")
    ax.set_ylabel("y-axis", fontsize=14, fontweight="bold")
    ax.set_yticks([-1, 0, 1, 2])
    ax.tick_params(labelsize=14)
    for label in ax.get_xticklabels() + ax.get_yticklabels():
        label.set_fontweight("bold")

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


if __name__ == "__main__":
    fig8_4()
