from matplotlib import pyplot as plt
import numpy as np
from snippets.plot import get_anchor

# Add some text to the plot.
fig, ax = plt.subplots()
texts = [
    ax.text(0.1, 0.5, "hello", fontsize=40),
    ax.text(
        0.6, 0.5, "world", fontsize=40, bbox={"boxstyle": "round,pad=0.5"}
    ),
]
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)

# Draw without rendering ensures the extent of all artists is computed.
fig.draw_without_rendering()

# Find the anchors at different positions and plot them.
hours = np.arange(12)
for text in texts:
    anchors = [get_anchor(text, hour) for hour in hours]
    ax.scatter(*np.transpose(anchors), c=hours, zorder=9)