I use matplotlib to build some data that I want to comment with arrows (distance markers). These arrows should be offset by several points so as not to overlap with line data:
import matplotlib.pyplot as plt
import matplotlib.transforms as transforms
fig, ax = plt.subplots()
x = [0, 1]
y = [0, 0]
ax.plot(x, y)
dy = 5/72
offset = transforms.ScaledTranslation(0, dy, ax.get_figure().dpi_scale_trans)
verttrans = ax.transData+offset
ax.plot(x, y, transform = verttrans)
ax.annotate("", (0,0), (1,0),
size = 10,
transform=verttrans,
arrowprops = dict(arrowstyle = '<|-|>'))
plt.show()
Is there any way to make the lines drawn ax.annotate()by offset points of X? I want to use absolute coordinates (for example, points or inches) instead of data coordinates, since the limits of the axis are subject to change.
Thank!
source
share