是否可以使用Plotly生成时钟图?

发布于 2025-02-07 05:14:25 字数 721 浏览 1 评论 0原文

我正在开发一个dataviz项目,并遇到了Last.FM生成的报告,其中有一个时钟图来表示记录按小时分配。

所讨论的图表是:

“

它是一个交互式图形,所以我尝试使用plotly库来尝试复制图表,但没有成功。

有什么方法可以在情节中复制这一点?这是我需要代表的数据

listeningHour  = df.hour.value_counts().rename_axis('hour').reset_index(name='counts')
listeningHour
   hour counts
0   17  16874
1   18  16703
2   16  14741
3   19  14525
4   23  14440
5   22  13455
6   20  13119
7   21  12766
8   14  11605
9   13  11575
10  15  11491
11  0   10220
12  12  7793
13  1   6057
14  9   3774
15  11  3476
16  10  1674
17  8   1626
18  2   1519
19  3   588
20  6   500
21  7   163
22  4   157
23  5   26

I'm developing a dataviz project and I came across the report generated by Last.FM, in which there is a clock chart to represent the distribution of records by hours.

The chart in question is this:

this

It is an interactive graph, so I tried to use the Plotly library to try to replicate the chart, but without success.

Is there any way to replicate this in Plotly? Here are the data I need to represent

listeningHour  = df.hour.value_counts().rename_axis('hour').reset_index(name='counts')
listeningHour
   hour counts
0   17  16874
1   18  16703
2   16  14741
3   19  14525
4   23  14440
5   22  13455
6   20  13119
7   21  12766
8   14  11605
9   13  11575
10  15  11491
11  0   10220
12  12  7793
13  1   6057
14  9   3774
15  11  3476
16  10  1674
17  8   1626
18  2   1519
19  3   588
20  6   500
21  7   163
22  4   157
23  5   26

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮色兮凉城 2025-02-14 05:14:25

Platly提供的图是极性条形图。我已经使用您的数据编写了一个代码。在我的研究时,似乎没有一种将tick滴在甜甜圈内的方法。代码的点是从角度轴的方向从0:00开始。时钟显示为24个带有空字符串和每6小时字符串的tick位置的列表。角度网格与条形图的中心对齐。

import plotly.graph_objects as go

r = df['counts'].tolist()
theta = np.arange(7.5,368,15)
width = [15]*24

ticktexts = [f'$\large{i}

if i % 6 == 0 else '' for i in np.arange(24)] fig = go.Figure(go.Barpolar( r=r, theta=theta, width=width, marker_color=df['counts'], marker_colorscale='Blues', marker_line_color="white", marker_line_width=2, opacity=0.8 )) fig.update_layout( template=None, polar=dict( hole=0.4, bgcolor='rgb(223, 223,223)', radialaxis=dict( showticklabels=False, ticks='', linewidth=2, linecolor='white', showgrid=False, ), angularaxis=dict( tickvals=np.arange(0,360,15), ticktext=ticktexts, showline=True, direction='clockwise', period=24, linecolor='white', gridcolor='white', showticklabels=True, ticks='' ) ) ) fig.show()

The graph provided by Plotly is a polar bar chart. I have written a code using it with your data. At the time of my research, there does not seem to be a way to place the ticks inside the doughnut. The point of the code is to start at 0:00 in the direction of the angle axis. The clock display is a list of 24 tick places with an empty string and a string every 6 hours. The angle grid is aligned with the center of the bar chart.

import plotly.graph_objects as go

r = df['counts'].tolist()
theta = np.arange(7.5,368,15)
width = [15]*24

ticktexts = [f'$\large{i}

enter image description here

if i % 6 == 0 else '' for i in np.arange(24)] fig = go.Figure(go.Barpolar( r=r, theta=theta, width=width, marker_color=df['counts'], marker_colorscale='Blues', marker_line_color="white", marker_line_width=2, opacity=0.8 )) fig.update_layout( template=None, polar=dict( hole=0.4, bgcolor='rgb(223, 223,223)', radialaxis=dict( showticklabels=False, ticks='', linewidth=2, linecolor='white', showgrid=False, ), angularaxis=dict( tickvals=np.arange(0,360,15), ticktext=ticktexts, showline=True, direction='clockwise', period=24, linecolor='white', gridcolor='white', showticklabels=True, ticks='' ) ) ) fig.show()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文