1

I am trying to plot times by each hour

    time_new=[x[:2]+":"+x[2:] for x in time_cleaned]        
    hour_list = [t[:2] for t in time_new]
    print hour_list
    numbers=[x for x in xrange(0,24)]
    labels=map(lambda x: str(x), numbers)
    plt.xticks(numbers, labels)
    plt.xlim(0,24)
    pdb.set_trace()
    plt.hist(hour_list)
    plt.show()

I get this error TypeError: 'len() of unsized object' in line plt.hist(hour_list)

pprint(time_new)
['09:00',
 '23:30',
 '19:05',
 '09:00',
 '01:00',
 '02:00',
 '19:00',
 '05:30',
 '04:00',
 '20:00',
 '23:30',
 '10:30',
 '20:00',
 '05:0',
 '21:30',
 '17:30',
 '04:55',
 '13:45',
 '08:40',
 '13:00',
 '06:00',
 '19:45',
 '09:00',
 '14:30',
 '09:00',
 '10:30',
 '23:07',
 '19:00',
 '23:40',
 '20:30',
 '19:30',
 '06:00',
 '05:30',
 '24:00',
 '20:30',
 '19:00',
 '15:05',
 '14:15',
 '19:20',
 '14:00',
 '15:15',
 '21:00']
(Pdb) 

Edit: Fixed it by:

hour_list = [int(t[:2]) for t in time_new]

By I am incorrect hist. enter image description here

Edit 2: enter image description here

Abhishek Bhatia
  • 9,404
  • 26
  • 87
  • 142
  • 1
    How is this different from your previous [question](http://stackoverflow.com/questions/32451265/histogram-of-time)? – EdChum Sep 08 '15 at 07:50
  • This is primitive code, works only on number of hours. I refering to the error here. I can't understand the error. `len(hour_list)` seems to work fine. – Abhishek Bhatia Sep 08 '15 at 07:52
  • There is insufficient data here to reproduce your error, post raw input data and your code to make your df – EdChum Sep 08 '15 at 07:53
  • Your edit is not an edit, it's an answer. And, in fact, it's the answer given by @rurp below (so it would be a nice gesture to accept his answer, even if you'd found it yourself). Don't try to ask a new question in an edit to the old one - it just makes everything confusing for readers who find this question (e.g. from google) – J Richard Snape Sep 08 '15 at 08:33
  • My recommendation is that you take the two histograms from the question and make a new question about how you can get the exact format of 24 bins you want (e.g. - if passing `bins=24` doesn't work for you, why not?) – J Richard Snape Sep 08 '15 at 08:39

1 Answers1

2

It looks like you are trying to plot strings as values. Try changing hour_list to:

hour_list = [int(t[:2]) for t in time_new]
rurp
  • 1,376
  • 2
  • 14
  • 22