Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot points on a clock

I have times in seconds since the start of the Unix epoch. I would like to plot them on a 24 hour clock. My effort so far is

from __future__ import division
import matplotlib.pyplot as plt
import numpy as np
angles = 2*np.pi*np.random.randint(0,864000,100)/86400
ax = plt.subplot(111, polar=True)
ax.scatter(angles, np.ones(100)*1)
plt.show()

This gives the following

Attempt to plot on a clock

However, it's not exactly what I would like.

  • How can I put the points on the circumference not in the interior (or at least move them further out from the center)?
  • How can I change the labels from angles to times?
  • How can I get rid of 0.2, 0.4, ...?
  • Basically, how can I make it look more like points marked on a clock?
like image 741
graffe Avatar asked Sep 17 '14 19:09

graffe


1 Answers

from __future__ import division
import matplotlib.pyplot as plt
import numpy as np
from numpy import pi

angles = 2*pi*np.random.randint(0,864000,100)/86400
ax = plt.subplot(111, polar=True)
ax.scatter(angles, np.ones(100)*1)

# suppress the radial labels
plt.setp(ax.get_yticklabels(), visible=False)

# set the circumference labels
ax.set_xticks(np.linspace(0, 2*pi, 24, endpoint=False))
ax.set_xticklabels(range(24))

# make the labels go clockwise
ax.set_theta_direction(-1)

# place 0 at the top
ax.set_theta_offset(pi/2.0)    

# plt.grid('off')

# put the points on the circumference
plt.ylim(0,1)

plt.show()

enter image description here

Or, to make better use of the face of the clock, you could replace the scatter plot with a bar plot (inspiration for this came from this codegolf answer):

# ax.scatter(angles, np.ones(100)*1, marker='_', s=20)
ax.bar(angles, np.full(100, 0.9), width=0.1, bottom=0.0, color='r', linewidth=0)

enter image description here

Or, to make the bars look more like ticks, you could set bottom=0.89:

ax.bar(angles, np.full(100, 0.9), width=0.05, bottom=0.89, color='r', linewidth=0)

enter image description here

like image 173
unutbu Avatar answered Sep 20 '22 00:09

unutbu