import matplotlib
import matplotlib.pyplot as plt
import pandas as pd

mplparams = {
    "text.usetex": True,
    "axes.linewidth": 1,
    "axes.grid": False,
    "axes.labelweight": "normal",
    "font.family": "DejaVu Sans",
    "font.size": 40,
}
matplotlib.rcParams.update(mplparams)

GA = 1
GC = "#808080ff"
LW = 3

f0_lim = (25, 125)
mv_lim = [5.168446695179246e-14, 2.581867744851853e-13]
f0_opt = 50.34

fig, ax = plt.subplots(figsize=[16, 10])
ax.tick_params(which="both", axis="both")
ax.set_xlabel(r"$f_0$ [Hz]")
ax.set_ylabel("Strain [-]")

df = pd.read_csv("o4a_vbc_cygx1_ul.csv")
ax.step(
    df.frequency,
    df.ul,
    color="black",
    where="mid",
    marker="none",
    ms=10,
    lw=LW,
    label=r"95\% CL UL",
)
ax.axvline(f0_opt, ls="--", c="black", lw=LW, label=r"$m_V^{\rm opt}$")

ax.legend(loc="upper right", ncol=2)
ax.set_xlim(*f0_lim)
ax.set_ylim(7e-26, 2e-24)
ax.set_yscale("log")

ax1 = ax.twiny()
ax1.xaxis.tick_bottom()
ax1.xaxis.set_label_position("bottom")
ax1.set_xlim(*mv_lim)
ax1.set_xlabel(r"$m_V$ [eV]")

ax.xaxis.tick_top()
ax.xaxis.set_label_position("top")
ax.xaxis.set_label_coords(0.5, 1.15)

ax.grid(c=GC, which="both", axis="y", alpha=GA)
ax1.grid(c=GC, which="both", axis="x", alpha=GA)

fig.tight_layout()
# fig.savefig("bsd_ul.pdf", transparent=True, bbox_inches="tight")
plt.show()
