matplotlib.pyplot.annotate():在子图上放置一个带有'axes fraction'坐标的文本

时间:2015-06-23 18:49:56

标签: python python-2.7 matplotlib plot annotate

当我在水平轴上使用大数字时,我遇到了一些matplotlib.pyplot.annotate()的问题,例如在“自纪元以来的秒数”中使用时间数据进行时间序列,其中数据将达到10 ^ 9。

以下是一个例子:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

import os.path

import random

import calendar

save_path='my_path'

fig,ax=plt.subplots(2,sharex=True)
fig.set_size_inches(6,5)

a=int(calendar.timegm((2009,1,1,0,0,0)))
b=int(calendar.timegm((2009,2,1,0,0,0)))
x=xrange(a,b,(b-a)/100)
#x=xrange(0,b-a,(b-a)/100)

y=[random.random() for i in x]
z=[random.random() for i in x]

ax[0].scatter(x,y)
ax[1].scatter(x,z)

for sub in ax:
    sub.set_xlim(x[0],x[-1])

ax[0].annotate('test',(0.1,0.1),textcoords='axes fraction')
ax[1].annotate('test',(0.9,0.9),textcoords='axes fraction')

fig.savefig(os.path.join(save_path,'test.png'),bbox_inches='tight')
plt.close()

x=xrange(a,b,(b-a)/100) 我明白了: enter image description here

x=xrange(0,b-a,(b-a)/100)同时 我明白了: enter image description here

我不明白为什么第一种情况不起作用,但第二种情况按预期工作,我只是基本上减少了数字。 如果我使用'data'坐标,我没有问题。

0 个答案:

没有答案