如何创建时钟极坐标图?

How to creat a clock polar chart?

import numpy as np
import matplotlib.pyplot as plt


# Compute areas and colors

r= dt.iloc[0:9,2]
theta = dt.iloc[0:9,1]
area = r
colors = r

fig = plt.figure()[![enter image description here][1]][1]
ax = fig.add_subplot(projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)





data= {'device': {0: 'Laptop', 1: 'Laptop', 2: 'Laptop', 3: 'Laptop', 4: 'Laptop'},
'power': {0: 20, 1: 23, 2: 20, 3: 22, 4: 19},
'time': {0: '16/11/2012 11:29',
 1: '16/11/2012 11:30',
 2: '16/11/2012 11:31',
 3: '16/11/2012 11:32',
 4: '16/11/2012 11:33'},
 'time_string': {0: '16/11/2012 11:29',
 1: '16/11/2012 11:30',
 2: '16/11/2012 11:31',
 3: '16/11/2012 11:32',
 4: '16/11/2012 11:33'},
 'x': {0: 0.17, 1: 0.17, 2: 0.17, 3: 0.17, 4: 0.17},
 'y': {0: 0.48, 1: 0.48, 2: 0.48, 3: 0.48, 4: 0.48}}

您好,我想创建一个时钟图表以在时钟表示中按时间显示功耗。我们如何在极坐标周围添加精确的时钟编号?以及我们如何通过时钟中的时间来显示权力?谁能帮我解决这个问题?提前致谢。

图片=
1:

正如我评论的那样,我添加了一个像 24 小时制一样的刻度标签,0:00 设置在顶部,参考 @unutbu's answer。 创建对应于 24 小时 x 60 分钟角度的等距序列。将时间序列数据的小时和分钟转换为分钟。这个分数是之前创建的数字序列的索引。 我更改了您的一些数据,以便更容易在图表中查看结果。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data= {'device': {0: 'Laptop', 1: 'Laptop', 2: 'Laptop', 3: 'Laptop', 4: 'Laptop'},
'power': {0: 60, 1: 23, 2: 120, 3: 22, 4: 49},
'time': {0: '16/11/2012 11:29',
 1: '16/11/2012 12:30',
 2: '16/11/2012 13:31',
 3: '16/11/2012 14:32',
 4: '16/11/2012 15:33'},
 'time_string': {0: '16/11/2012 11:29',
 1: '16/11/2012 11:30',
 2: '16/11/2012 11:31',
 3: '16/11/2012 11:32',
 4: '16/11/2012 11:33'},
 'x': {0: 0.17, 1: 0.17, 2: 0.17, 3: 0.17, 4: 0.17},
 'y': {0: 0.48, 1: 0.48, 2: 0.48, 3: 0.48, 4: 0.48}}

df = pd.DataFrame(data)
df['time'] = pd.to_datetime(df['time'])
df['seconds'] = df['time'].dt.hour*60+df['time'].dt.minute

# Compute areas and colors
hour_minute = np.linspace(0, 2*np.pi, 24*60, endpoint=False)

r= df.iloc[0:9,1].tolist()
theta = df.iloc[0:9,1]
area = r
colors = r

fig = plt.figure()
ax = fig.add_subplot(projection='polar')
ax.scatter(hour_minute[df['seconds']], r, s=area, c=colors, cmap='hsv', alpha=0.75)
ax.set_rgrids(np.arange(0,df['power'].max(),20), angle=90)

# clock labels
ax.set_xticks(np.linspace(0, 2*np.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(np.pi/2.0) 

plt.show()