commands: add --density flag to times graph

This commit is contained in:
Frédéric Péters 2020-08-05 08:00:29 +02:00
parent 8443c4b1ae
commit af04cf99d9
1 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import datetime
import matplotlib
import matplotlib.colors
import matplotlib.dates
import matplotlib.pyplot as plt
@ -13,6 +14,7 @@ class Command(GraphCommand):
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument('--opacity', type=float, default=0.3)
parser.add_argument('--density', action='store_true')
def handle(self, *args, **options):
datetime_var = 'author_datetime'
@ -28,7 +30,12 @@ class Command(GraphCommand):
graph_date -= datetime.timedelta(hours=4)
event_dates.append(matplotlib.dates.date2num(graph_date.date()))
event_times.append(graph_date.hour + graph_date.minute / 60. + graph_date.second / 3600)
plot = plt.scatter(event_dates, event_times, alpha=options.get('opacity'))
if options.get('density'):
plot = plt.hist2d(event_dates, event_times, bins=(100, 100),
cmap=plt.cm.jet, norm=matplotlib.colors.LogNorm())
plt.colorbar()
else:
plot = plt.scatter(event_dates, event_times, alpha=options.get('opacity'))
plots.append((legend, plot))
if i > 1: