我有点麻烦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)
我得到:
使用x=xrange(0,b-a,(b-a)/100)时
我得到:
我不明白为什么第一种情况不起作用,但第二种情况如预期的那样有效,我只是基本上减少了数字。
如果我使用“数据”坐标,我没有问题。在