aboutsummaryrefslogtreecommitdiffstats
path: root/onceaday/graph.py
blob: 723997b61a75982f9630fd2fe342e212d78c6b52 (plain)
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
27
28
29
30
31
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt
import matplotlib
import datetime

def make_graph(data):
    fig = plt.figure()
    
    lambdaCount = [i[1] for i in data]
    helpGiven = [i[2] for i in data]
    uniqueUsers = [i[3] for i in data]
    date = [datetime.datetime.strptime(i[4], "%Y-%m-%d") for i in data]

    fig, ax1 = plt.subplots()
    ax1.plot(date, lambdaCount, label = "Total λ in circulation", color = "r")
    ax1.set_ylabel("Total λ / help given")

    ax1.plot(date, helpGiven, label = "Times help given", color = "g")
    
    ax2 = ax1.twinx()
    ax2.plot(date, uniqueUsers, label = "Unique users")
    ax2.set_ylabel("No. Unique Users")

    ax1.legend()
    ax2.legend(loc = 4)
    fig.autofmt_xdate()

    filepath = "graph.png"
    fig.savefig(filepath)
    return filepath