Through a panel of 2 lists make a chart

Asked

Viewed 74 times

0

I have 1 table with 2 lists as for example the following ones , where the first one contains dates in the YYYYMMDD format and the second one 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, and abscissas correspond to the years and ordered 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 chart however it does only one thing that is my doubt, what I can do and then change in my code so that the abscissas in this case the x , take into account the years with 365 and 366 days , because supposedly with 365 the axis width will be smaller and with 366 will be bigger

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. Know that if the year is leap 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 that will have the list with the number of days that passed to the year in question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.