1

I have some trouble with matplotlib.pyplot.annotate() when I use big numbers in the horizontal axis, for example doing time series with time data in "seconds since epoch" where the data will reach 10^9.

Here is an example:

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()

With x=xrange(a,b,(b-a)/100) I get: enter image description here

While with x=xrange(0,b-a,(b-a)/100) I get: enter image description here

I don't understand why the first case doesn't work but the second case works as expected, I just reduced the numbers basically. I have no problems if I use 'data' coordinates though.

Greenfire
  • 103
  • 1
  • 7
  • 1
    Can you make your example code shorter? There is way too much code there to get people to read it to help you. You will get better help if you make it easy for others to help you. – tacaswell Jun 24 '15 at 01:22
  • Yes sorry, I just put something simpler – Greenfire Jun 25 '15 at 20:37
  • Is the question still badly formulated? Should I have deleted and recreated the post instead of simply editing? – Greenfire Jun 29 '15 at 14:47
  • No, definitely do not open a new question, that tends to _really_ annoy people. The question looks much better now. – tacaswell Jun 29 '15 at 15:33

0 Answers0