Through a tuple of 2 lists make a graph

0

I have 1 tuple with 2 ready lists like for example the following ones, in which the first contains dates in the format YYYYMMDD and the second contains the number of times a crime happened that day.

tuplo= (['20160130', '20160230', '20160330', '20160430', '20160530', '20160730'] [1, 2, 2, 2, 1, 1])

What I intend to do is a function that shows a graph with the number of crimes that occurred each day, the abscissa corresponding to the years and the ordinances to the number of crimes.

def fazer_grafico(tuplo):

    x = list()
    for anos in tuplo[0]:
        x.append(anos[:4])
     # x é uma lista só com os anos

    x_tmp = range(0, len(x), len(x)/len(set(x)))
    y= grafico[1]


    pylab.plot(range(len(x)), y)
    x= sorted(set(x))
    x.append(" ")
    pylab.xticks(x_tmp,sorted(set(y)))

The function is doing the correct graphic however does only do one thing that is my doubt, what can I do and then change in my code so that the abscissas in this case x, take into account the years with 365 and 366 days, because supposedly with 365 the width of the axis will be smaller and with 366 going to be larger

    
asked by anonymous 26.05.2016 / 16:34

1 answer

2

Instead of creating x_tmp like this:

x_tmp = range(0, len(x), len(x)/len(set(x)))

Create according to the year in question. You know that if the leap year is divisible by 4, otherwise it is not, for example:

x_tmp = [0]
Para cada ano de sorted(set(x)):
    Se ano bissexto:
        adicionar 366 à ultima entrada de x_tmp e fazer append a x_tmp
    Caso contrário:
        adicionar 365 à ultima entrada de x_tmp e fazer append a x_tmp

I think this will be the case with the number of days that have passed the year in question.

    
29.05.2016 / 12:12