如果x坐标为负,文本为什么会离开轴?

时间:2015-08-26 18:48:39

标签: python-2.7 matplotlib

在下面的例子中,我希望两种情况下的文本都在同一个地方:

import matplotlib.pyplot as plt

x = range(-2,3) 
xi = -1

plt.plot(x,x)
plt.annotate('as expected',
            xy=(1, 1), xycoords='data',
            xytext=(.5, .8), textcoords='axes fraction',
            arrowprops=dict(arrowstyle='-'))                 
plt.annotate('why am i here?',
            xy=(xi, 0.5), xycoords='data',
            xytext=(.5, .8), textcoords='axes fraction',
            arrowprops=dict(arrowstyle='-'))

plt.show()

enter image description here

第二个注释中文本的位置在轴外,甚至 虽然我认为它应该与第一个注释在同一个地方。 这似乎发生在任何负值xi

1 个答案:

答案 0 :(得分:0)

请注意,对于物理坐标系(点或像素),原点(xy)是轴的(底部,左侧)。如果值为负,则原点来自轴的(右侧,顶部)。