import matplotlib.pyplot as plt
import numpy as np
def draw_clock(hour, minute):
fig, ax = plt.subplots(figsize=(6,6))
# 時計の外枠を描画
clock_face = plt.Circle((0,0), 1, fill=False, linewidth=2)
ax.add_patch(clock_face)
# 目盛りを描画
for i in range(60):
angle = np.deg2rad(90 - i * 6)
x_start = np.cos(angle)
y_start = np.sin(angle)
if i % 5 == 0:
# 5分ごとの長めの目盛り
x_end = 0.85 * np.cos(angle)
y_end = 0.85 * np.sin(angle)
linewidth = 2
else:
# 1分ごとの短めの目盛り
x_end = 0.9 * np.cos(angle)
y_end = 0.9 * np.sin(angle)
linewidth = 1
ax.plot([x_start, x_end], [y_start, y_end], color='black', linewidth=linewidth)
# 時間目盛りと数字を描画
for i in range(1, 13):
angle = np.deg2rad(90 - i * 30)
x_text = 0.75 * np.cos(angle)
y_text = 0.75 * np.sin(angle)
ax.text(x_text, y_text, str(i), horizontalalignment='center', verticalalignment='center', fontsize=24) # フォントサイズを大きく
# 時針を描画(矢印)
hour_angle = np.deg2rad(90 - (hour % 12 + minute / 60) * 30)
hour_x = 0.5 * np.cos(hour_angle)
hour_y = 0.5 * np.sin(hour_angle)
ax.arrow(0, 0, hour_x, hour_y, width=0.025, head_width=0.07, head_length=0.14, fc='black', ec='black', length_includes_head=True)
# 分針を描画(矢印)
minute_angle = np.deg2rad(90 - minute * 6)
minute_x = 0.8 * np.cos(minute_angle)
minute_y = 0.8 * np.sin(minute_angle)
ax.arrow(0, 0, minute_x, minute_y, width=0.015, head_width=0.06, head_length=0.12, fc='black', ec='black', length_includes_head=True)
# プロットの設定
ax.set_xlim(-1.1, 1.1)
ax.set_ylim(-1.1, 1.1)
ax.set_aspect('equal')
ax.axis('off')
plt.show()
draw_clock(3, 50)