Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot histogram of datetime.time python / matplotlib

I am trying to plot a histogram of datetime.time values. Where these values are discretized into five minute slices. The data looks like this, in a list:

['17:15:00', '18:20:00', '17:15:00', '13:10:00', '17:45:00', '18:20:00']

I would like to plot a histogram, or some form of distribution graph so that the number of occurrences of each time can be examined easily.

NB. Given each time is discretised then. The maximum number of bins in a histogram would be 288 = (60 / 5 * 24)

I have looked at matplotlib.pyplot.hist. But is requires some sort of continuous scalar

like image 535
Spacen Jasset Avatar asked Dec 03 '11 17:12

Spacen Jasset


People also ask

How do I plot time series data in Matplotlib?

In X-axis we should have a variable of DateTime. In Y-axis we can have the variable which we want to analyze with respect to time. plt. plot() method is used to plot the graph in matplotlib.

Can Matplotlib plot real time?

To create a real-time plot, we need to use the animation module in matplotlib. We set up the figure and axes in the usual way, but we draw directly to the axes, ax , when we want to create a new frame in the animation.

How do I create a histogram in Python Matplotlib?

In Matplotlib, we use the hist() function to create histograms. The hist() function will use an array of numbers to create a histogram, the array is sent into the function as an argument.


1 Answers

I did what David Zwicker said and used seconds, and then changed the x axis. I will look at what Dave said about 'bins'. This works roughly and gives a bar per hour plot to start with.

def chart(occurance_list):
    hour_list = [t.hour for t in occurance_list]
    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)
    plt.hist(hour_list)
    plt.show()

frequency of lowest daily exahange rate for GBPUSD

like image 164
Spacen Jasset Avatar answered Sep 27 '22 18:09

Spacen Jasset