comparison agl.py @ 18:156ab071a9de

Only print the start date if the duration is 1 day
author Daniel O'Connor <darius@dons.net.au>
date Mon, 11 Sep 2017 22:46:50 +0930
parents 227a2a524675
children 1d08f777533f
comparison
equal deleted inserted replaced
17:227a2a524675 18:156ab071a9de
278 ax1.text(0.02, 0.9, reduce(lambda a, b: a + '\n' + b, annotations), 278 ax1.text(0.02, 0.9, reduce(lambda a, b: a + '\n' + b, annotations),
279 transform = ax1.transAxes, bbox = dict(facecolor = 'red', alpha = 0.5), 279 transform = ax1.transAxes, bbox = dict(facecolor = 'red', alpha = 0.5),
280 ha = 'left', va = 'top') 280 ha = 'left', va = 'top')
281 ndays = int(max(1, round(((end - start).total_seconds()) / 86400))) 281 ndays = int(max(1, round(((end - start).total_seconds()) / 86400)))
282 for ax in fig.get_axes(): 282 for ax in fig.get_axes():
283 ax.set_title('%s to %s' % (startlt.strftime('%Y-%m-%d'), endlt.strftime('%Y-%m-%d'))) 283 if (endlt - startlt).total_seconds() > 86400:
284 ax.set_title('%s to %s' % (startlt.strftime('%Y-%m-%d'), endlt.strftime('%Y-%m-%d')))
285 else:
286 ax.set_title('%s' % (startlt.strftime('%Y-%m-%d')))
284 ax.set_xlim([start, end]) 287 ax.set_xlim([start, end])
285 ax.format_xdata = lambda d: matplotlib.dates.num2date(d).strftime('%d %b %H:%M') 288 ax.format_xdata = lambda d: matplotlib.dates.num2date(d).strftime('%d %b %H:%M')
286 ax.xaxis.grid(True) 289 ax.xaxis.grid(True)
287 ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%d %b\n%H:%M')) 290 ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%d %b\n%H:%M'))
288 ax.xaxis.set_major_locator(matplotlib.dates.HourLocator(interval = 2 * ndays)) 291 ax.xaxis.set_major_locator(matplotlib.dates.HourLocator(interval = 2 * ndays))