Wednesday, April 27, 2016

Plot histogram on a clock

Today I want to plot a histogram on a 24 hour clock (the data is aggregated from real life data that bined on each hour of the day). Here's the code, and you can download the code from Qingkai's Github.
In [1]:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%pylab inline
Populating the interactive namespace from numpy and matplotlib

(1) First generate random data from 0 - 23

In [2]:
arr = np.random.randint(0, 24, size = 500)

(2) Plot on the clock

In [3]:
N = 23
bottom = 2

# create theta for 24 hours
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)

# make the histogram that bined on 24 hour
radii, tick = np.histogram(arr, bins = 23)

# width of each bin on the plot
width = (2*np.pi) / N

# make a polar plot
plt.figure(figsize = (12, 8))
ax = plt.subplot(111, polar=True)
bars =, radii, width=width, bottom=bottom)

# set the lable go clockwise and start from the top
# clockwise

# set the label
ticks = ['0:00', '3:00', '6:00', '9:00', '12:00', '15:00', '18:00', '21:00']
In [ ]:


  1. I have read your blog its very attractive and impressive. I like it your blog...R Programming Training in Bangalore

  2. People tired to find a relevant place where they can know real facts and myths about the topic mentioned by author of this blog. I want to help a lot of needy people through this blog to come up at my blog to know the real facts and myths regarding this topic. นาฬิกา ถูก ๆ

  3. Such a informative post.Thanks for sharing your knowledge with us.keep it up for updating post..
    iot training in chennai | top 10 embedded training institutes in chennai .


  4. Thanks for sharing the descriptive information on Python tutorial. It’s really helpful to me since I'm taking Python training. Keep doing the good work and if you are interested to know more on Python, do check this Python tutorial.:-

  5. This information is impressive; I am inspired by your post writing style & how continuously you describe this topic.... Java Training in Chennai | Pega Training in Chennai

  6. Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.
    fire and safety course in chennai

  7. Best R Programming Training in Bangalore offered by myTectra. India's No.1 R Programming Training Institute. Classroom, Online and Corporate training in R Programming
    r programming training

  8. Thanks for posting useful information. You have provided a nice article, Thank you very much for this one. Java Training in Chennai | Pega Training in Chennai

  9. I have heard great things about Is there a way I can transfer all my Word Press posts into it? Any help would be appreciated.
    nebosh course in chennai

  10. Very helpful and attractive, many thanks. Small correction I think- N = 24? You can see the segments are very slightly too big.

  11. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us @ Best Travels in Madurai | Tours and Travels in Madurai | Madurai Travels