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

from plot_helpers import CO, bold_ticks


def fig6_14(ic=1):
    ### also also inclues fig6_15

    ### pick case: ic=1 => fig6_14   ic=2 => fig6_15

    # evaluate integrand for plotting
    a = 0
    b = 4
    nx = 200
    x = np.linspace(a - 0.1, b + 0.1, nx)
    y = np.zeros(nx)
    for ix in range(nx):
        y[ix] = f(x[ix])

    plt.close("all")
    # get(gcf)
    fig, ax = plt.subplots(figsize=(8.8, 3.3))
    fig.subplots_adjust(left=0.08, right=0.98, bottom=0.22, top=0.98)
    ax.set_prop_cycle(cycler(color=CO))

    ax.plot(x, y, "r", linewidth=2)
    ax.set_xlim(x[0], x[nx - 1])
    ax.set_ylim(0, 3)
    ax.set_xlabel("x-axis")
    ax.set_ylabel("y-axis")
    bold_ticks(ax, 14)

    if ic == 1:
        xx = 0
        ax.plot([xx, xx], [0, f(xx)], "b", linewidth=1.6)
        xx = b / 2
        ax.plot([xx, xx], [0, f(xx)], "b", linewidth=1.6)
        xx = b
        ax.plot([xx, xx], [0, f(xx)], "b", linewidth=1.6)
        xx = b / 4
        ax.plot([xx, xx], [0, f(xx)], "--b", linewidth=1.6)
        xx = 3 * b / 4
        ax.plot([xx, xx], [0, f(xx)], "--b", linewidth=1.6)
        # plt.savefig('/Users/mark/Desktop/aq0.eps')
    else:
        xx = 0
        ax.plot([xx, xx], [0, f(xx)], "b", linewidth=1.6)
        xx = b / 4
        ax.plot([xx, xx], [0, f(xx)], "b", linewidth=1.6)
        xx = b / 2
        ax.plot([xx, xx], [0, 0.98 * f(xx)], "b", linewidth=4)
        xx = 3 * b / 4
        ax.plot([xx, xx], [0, f(xx)], "b", linewidth=1.6)
        xx = b
        ax.plot([xx, xx], [0, f(xx)], "b", linewidth=1.6)
        xx = b / 4
        ax.plot([xx, xx], [0, f(xx)], "--b", linewidth=1.6)
        xx = 3 * b / 4
        ax.plot([xx, xx], [0, f(xx)], "--b", linewidth=1.6)
        xx = b / 8
        ax.plot([xx, xx], [0, f(xx)], "--b", linewidth=1.6)
        xx = 3 * b / 8
        ax.plot([xx, xx], [0, f(xx)], "--b", linewidth=1.6)
        xx = 5 * b / 8
        ax.plot([xx, xx], [0, f(xx)], "--b", linewidth=1.6)
        xx = 7 * b / 8
        ax.plot([xx, xx], [0, f(xx)], "--b", linewidth=1.6)
        # plt.savefig('/Users/mark/Desktop/aq2.eps')

    plt.show()


def f(x):
    # 1 + Lorentzian Function
    g = 0.5 * 2 / np.pi
    x0 = 3
    gg = g / 2
    y = 1 + (gg / np.pi) / ((x - x0) ** 2 + gg ** 2)
    return y


if __name__ == "__main__":
    fig6_14()
