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


def fig5_2R():
    a = -1
    b = 1
    nx = 10
    x = np.linspace(a, b, nx)

    # sum series
    p = 4 / 3
    y = np.zeros(nx)
    for ix in range(nx):
        sum = 0
        for in_ in range(1, 2001):
            sum = sum + (-1) ** in_ * np.cos(in_ * np.pi * x[ix] / b) / (in_ ** p)
        y[ix] = b ** 2 / 3 + sum * 4 * b ** 2 / np.pi ** 2

    plt.close("all")
    # get(gcf)
    fig, ax = plt.subplots(figsize=(7.0, 5.25))
    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))

    ax.plot(x, y, "or", markersize=12, linewidth=3)
    ax.set_xlim(-1.1, 1.1)
    ax.set_ylim(-0.1, 2)
    ax.grid(True)
    ax.set_xlabel("x-axis")
    ax.set_ylabel("y-axis")
    ax.tick_params(labelsize=24)
    for label in ax.get_xticklabels() + ax.get_yticklabels():
        label.set_fontweight("bold")
    for spine in ax.spines.values():
        spine.set_visible(True)
    fig.tight_layout()
    plt.show()


if __name__ == "__main__":
    fig5_2R()
