from matplotlib import pyplot as plt
from matplotlib import patches
import numpy as np

fig = plt.figure(figsize=(4, 3))
ax = fig.add_subplot(aspect=1)
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])
ax.set_frame_on(False)

# Origin
ax.plot(0, 0, ".", markersize=10, color="black")

# Antenna
ax.text(0.45, -0.05, "Antenna", ha="center", va="top")
ax.annotate(
    "",
    xy=(0, 0),
    xytext=(0.9, 0),
    xycoords="data",
    textcoords="data",
    arrowprops=dict(arrowstyle="<-"),
)

# Earth
ax.text(1, 0, "    Earth", va="center")
markersize = 16
for marker in "o+":
    ax.plot(
        1,
        0,
        marker=marker,
        markerfacecolor="white",
        color="black",
        markeredgewidth=1,
        markersize=markersize,
        clip_on=False,
    )

# Sun
# ax.text(-1, 0, "Sun   ", ha="right", va="center")
for sun_angle in np.arange(15, 180, 15):
    color = str(sun_angle / 180)
    angle = np.deg2rad(180 + sun_angle)
    x = np.cos(angle)
    y = np.sin(angle)
    ax.plot(
        x,
        y,
        marker="o",
        markerfacecolor="white",
        color=color,
        markeredgewidth=1,
        markersize=markersize,
        clip_on=False,
    )
    ax.plot(
        x,
        y,
        marker=".",
        color=color,
        markeredgewidth=1,
        clip_on=False,
    )

ax.add_patch(
    patches.Arc((0, 0), width=0.5, height=0.5, theta1=135, theta2=180, linestyle="--")
)
angle = np.deg2rad((135 + 180) / 2)
ax.text(0.25 * np.cos(angle), 0.25 * np.sin(angle), "≥45°", ha="right", va="baseline")
ax.annotate(
    "Sun  ",
    xy=(0, 0),
    xytext=(-0.9, 0),
    xycoords="data",
    textcoords="data",
    ha="right",
    va="center",
    arrowprops=dict(arrowstyle="<-", linestyle="--"),
)

# Boresight
ax.annotate(
    "Boresight",
    xy=(0, 0),
    xytext=(-np.sqrt(2) / 2, np.sqrt(2) / 2),
    xycoords="data",
    textcoords="data",
    arrowprops=dict(arrowstyle="<-"),
    ha="right",
    va="bottom",
    rotation=-45,
    clip_on=False,
)

# Mark angle
ax.add_patch(patches.Arc((0, 0), width=0.5, height=0.5, theta1=0, theta2=135))
angle = np.deg2rad(135 / 2)
ax.text(0.25 * np.cos(angle), 0.25 * np.sin(angle), "135°", ha="left", va="bottom")