2014-09-17 2 views
3

У меня есть время в секундах с момента начала эпохи Unix. Я хотел бы построить их на 24-часовых часах. Мои усилия до сих порКак построить точки на часах

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() 

Это дает следующую

Attempt to plot on a clock

Однако, это не совсем то, что я хотел.

  • Как я могу поместить точки по окружности не в интерьере (или хотя бы вывести их дальше от центра)?
  • Как изменить метки от углов до времени?
  • Как я могу избавиться от 0.2, 0.4, ...?
  • В принципе, как я могу заставить его больше напоминать точки, отмеченные на часах?

ответ

4
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

Или, чтобы лучше использовать циферблат, вы могли бы заменить scatter участок с bar сюжетом (вдохновение для этого пришло из 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

Или, чтобы бары выглядели м руды, как клещи, вы можете установить 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

+1

Если вы хотите тиков, возможно построить небольшие отрезки. –

Смежные вопросы