#!/usr/bin/python

import matplotlib        as mpl
mpl.use("cairo")
import matplotlib.pyplot as plt

fig = plt.figure()
subplot = fig.add_subplot(1,1,1)

# The following is very sensitive to directive order
subplot.set_xticks([1341100800.0, 1343779200.0, 1346457600.0, 1349049600.0, 1351728000.0, 1354320000.0, 1356998400.0, 1359676800.0, 1362096000.0, 1364774400.0, 1367366400.0, 1370044800.0])
subplot.set_xticks([1340582400.0, 1341187200.0, 1341792000.0, 1342396800.0, 1343001600.0, 1343606400.0, 1344211200.0, 1344816000.0, 1345420800.0, 1346025600.0, 1346630400.0, 1347235200.0, 1347840000.0, 1348444800.0, 1349049600.0, 1349654400.0, 1350259200.0, 1350864000.0, 1351468800.0, 1352073600.0, 1352678400.0, 1353283200.0, 1353888000.0, 1354492800.0, 1355097600.0, 1355702400.0, 1356307200.0, 1356912000.0, 1357516800.0, 1358121600.0, 1358726400.0, 1359331200.0, 1359936000.0, 1360540800.0, 1361145600.0, 1361750400.0, 1362355200.0, 1362960000.0, 1363564800.0, 1364169600.0, 1364774400.0, 1365379200.0, 1365984000.0, 1366588800.0, 1367193600.0, 1367798400.0, 1368403200.0, 1369008000.0, 1369612800.0, 1370217600.0, 1370822400.0, 1371427200.0, 1372032000.0], minor=True)
subplot.set_xticklabels([])
plt.xlim(1341100800.0,1372636799.99)

subplot1 = subplot.twiny()
subplot1.set_xticks([1342439999.9949999, 1345118399.9949999, 1347753599.9949999, 1350388799.9949999, 1353023999.9949999, 1355659199.9949999, 1358337599.9949999, 1360886399.9949999, 1363435199.9949999, 1366070399.9949999, 1368705599.9949999, 1371340799.9949999])
subplot1.set_xticklabels(['2012-07', '2012-08', '2012-09', '2012-10', '2012-11', '2012-12', '2013-01', '2013-02', '2013-03', '2013-04', '2013-05', '2013-06'])
subplot1.tick_params(labelsize='6.5',labelbottom=True, labeltop=False)
plt.xlim(1341100800.0,1372636799.99)

subplot2 = subplot.twiny()
subplot2.set_xticks([1340884799.9949999, 1341489599.9949999, 1342094399.9949999, 1342699199.9949999, 1343303999.9949999, 1343908799.9949999, 1344513599.9949999, 1345118399.9949999, 1345723199.9949999, 1346327999.9949999, 1346932799.9949999, 1347537599.9949999, 1348142399.9949999, 1348747199.9949999, 1349351999.9949999, 1349956799.9949999, 1350561599.9949999, 1351166399.9949999, 1351771199.9949999, 1352375999.9949999, 1352980799.9949999, 1353585599.9949999, 1354190399.9949999, 1354795199.9949999, 1355399999.9949999, 1356004799.9949999, 1356609599.9949999, 1357214399.9949999, 1357819199.9949999, 1358423999.9949999, 1359028799.9949999, 1359633599.9949999, 1360238399.9949999, 1360843199.9949999, 1361447999.9949999, 1362052799.9949999, 1362657599.9949999, 1363262399.9949999, 1363867199.9949999, 1364471999.9949999, 1365076799.9949999, 1365681599.9949999, 1366286399.9949999, 1366891199.9949999, 1367495999.9949999, 1368100799.9949999, 1368705599.9949999, 1369310399.9949999, 1369915199.9949999, 1370519999.9949999, 1371124799.9949999, 1371729599.9949999, 1372334399.9949999])
subplot2.set_xticklabels([26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26])
subplot2.tick_params(labelsize='5',labelbottom=False, labeltop=True,pad=3)
plt.xlim(1341100800.0,1372636799.99)

subplot2.xaxis.set_ticks_position('none')
subplot1.xaxis.set_ticks_position('none')
subplot.xaxis.set_ticks_position('both')

fig.savefig('test.png')
plt.close()

