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:
JavaScript
x
24
24
1
import numpy as np
2
import matplotlib.pyplot as plt
3
4
# Array of values
5
values = np.array([[1,2,3], [1,2,3]])
6
7
# Line plot
8
fig, ax = plt.subplots()
9
plt.plot(values[0,:], values[1,:], 'bo-',label='$P_{1}$')
10
11
12
# Annotate the points of interest
13
ax.annotate('s', xy=(1.5, 0), xytext=(1.5, -0.8),
14
fontsize=1.5, ha='center', va='bottom',
15
bbox=dict(boxstyle='square', fc='white'),
16
arrowprops=dict(arrowstyle='-[, widthB=45.0, lengthB=1.5', lw=2.0))
17
18
ax.annotate('t-s', xy=(2.5, 0), xytext=(2.5, -0.8),
19
fontsize=1.5, ha='center', va='bottom',
20
bbox=dict(boxstyle='square', fc='white'),
21
arrowprops=dict(arrowstyle='-[, widthB=43.0, lengthB=2.5', lw=2.0))
22
23
plt.legend();
24
Advertisement
Answer
The coordinates of the annotations were set by axis and the position was set manually.
JavaScript
1
10
10
1
ax.annotate('s', xy=(0.275, -0.15), xytext=(0.275, -0.35),
2
fontsize=14, ha='center', va='bottom', xycoords='axes fraction',
3
bbox=dict(boxstyle='square', fc='0.8'),
4
arrowprops=dict(arrowstyle='-[, widthB=5.0, lengthB=.5', lw=2.0))
5
6
ax.annotate('t-s', xy=(0.725, -0.15), xytext=(0.725, -0.35),
7
fontsize=14, ha='center', va='bottom', xycoords='axes fraction',
8
bbox=dict(boxstyle='square', fc='0.8'),
9
arrowprops=dict(arrowstyle='-[, widthB=5.0, lengthB=.5', lw=2.0))
10