From e6ac0b2548d3d78c2a98f0d955b4dc8cef22730c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 2 Aug 2020 18:42:56 +0200 Subject: [PATCH] times: add markers on month ticks if graph spans less than a year --- eodb/events/management/commands/times.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/eodb/events/management/commands/times.py b/eodb/events/management/commands/times.py index d1a78cb..cb69735 100644 --- a/eodb/events/management/commands/times.py +++ b/eodb/events/management/commands/times.py @@ -4,6 +4,8 @@ import matplotlib import matplotlib.dates import matplotlib.pyplot as plt +from django.utils.dateparse import parse_date + from .common import GraphCommand @@ -33,9 +35,21 @@ class Command(GraphCommand): plt.legend([plot for legend, plot in plots], [legend for legend, plot in plots]) + if options.get('datemin'): + datemin = parse_date(options['datemin']) + else: + datemin = datetime.date(2000, 1, 1) # past + if options.get('datemax'): + datemax = parse_date(options['datemax']) + else: + datemax = datetime.date.today() + plt.gca().xaxis.set_major_locator(matplotlib.dates.YearLocator()) plt.gca().xaxis.set_minor_locator(matplotlib.dates.MonthLocator()) plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%m/%Y')) + if (datemax - datemin).days < 365: + plt.gca().xaxis.set_minor_formatter(matplotlib.dates.DateFormatter('%m/%Y')) + plt.gca().set_ylim([0, 24]) plt.yticks(range(24), list(range(4, 24)) + list(range(0, 4))) self.plot(options)