import matplotlib.pyplot as plt
# plot curves
curve_A = [6, 4, 2, 8]
curve_B = [12, 3, 1, 9]
x = range(len(curve_A))
fig = plt.figure()
ax = fig.add_subplot()
ax.plot(curve_A)
ax.plot(curve_B)
# make sure the curves "touch" the axes on the left
ax.set_xlim(x[0])
# get all limits
x_min, x_max = ax.get_xlim()
y_min, y_max = ax.get_ylim()
# define the annotation offset from the minimum x to the left
offset = 0.2
# annotate the first y-value of the curve A, placing the text below
ax.annotate("\nText A", (x_min - offset, curve_A[0]), (x_min - offset, y_min),
xycoords='data', textcoords='data',
size='large', color='k',
horizontalalignment='center', verticalalignment='top',
arrowprops=dict(
arrowstyle='<->',
shrinkA=0,
shrinkB=0
),
annotation_clip=False # required to see the annotation outside of the axes
)
# annotate the first y-value of the curve B, placing the text above
ax.annotate("Text B\n", (x_min - offset*2, y_min), (x_min - offset*2, curve_B[0]),
xycoords='data', textcoords='data',
size='large', color='k',
horizontalalignment='center', verticalalignment='bottom',
arrowprops=dict(
arrowstyle='<->',
shrinkA=0,
shrinkB=0
),
annotation_clip=False # required to see the annotation outside of the axes
)
plt.show()
Uma maneira de fazer isso é usar matplotlib.axes.Axes.annotate com um estilo de seta adequado e argumento annotation_clip definido como
False
:O resultado: