How can I take this plot and annotate or directly add an underbrace that adds some text between each word, followed I assume by moving the x-label down slightly to make it legible.
Example to create:

Starting code:
import numpy as np
import matplotlib.pyplot as plt
# Array of values
values = np.array([[1,2,3], [1,2,3]])
# Line plot
fig, ax = plt.subplots()
plt.plot(values[0,:], values[1,:], 'bo-',label='$P_{1}$')
# Annotate the points of interest
ax.annotate('s', xy=(1.5, 0), xytext=(1.5, -0.8),
            fontsize=1.5, ha='center', va='bottom',
            bbox=dict(boxstyle='square', fc='white'),
            arrowprops=dict(arrowstyle='-[, widthB=45.0, lengthB=1.5', lw=2.0))
ax.annotate('t-s', xy=(2.5, 0), xytext=(2.5, -0.8),
            fontsize=1.5, ha='center', va='bottom',
            bbox=dict(boxstyle='square', fc='white'),
            arrowprops=dict(arrowstyle='-[, widthB=43.0, lengthB=2.5', lw=2.0))
plt.legend();

The coordinates of the annotations were set by axis and the position was set manually.
ax.annotate('s', xy=(0.275, -0.15), xytext=(0.275, -0.35),
            fontsize=14, ha='center', va='bottom', xycoords='axes fraction', 
            bbox=dict(boxstyle='square', fc='0.8'),
            arrowprops=dict(arrowstyle='-[, widthB=5.0, lengthB=.5', lw=2.0))
ax.annotate('t-s', xy=(0.725, -0.15), xytext=(0.725, -0.35),
            fontsize=14, ha='center', va='bottom', xycoords='axes fraction', 
            bbox=dict(boxstyle='square', fc='0.8'),
            arrowprops=dict(arrowstyle='-[, widthB=5.0, lengthB=.5', lw=2.0))

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With