times: add markers on month ticks if graph spans less than a year
This commit is contained in:
parent
b5a4939646
commit
e6ac0b2548
|
@ -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)
|
||||
|
|
Reference in New Issue