【发布时间】:2021-07-25 11:30:02
【问题描述】:
我有以下熊猫数据框:
month stories comments comment_authors story_authors
0 2006-10 49 12 4 16
1 2007-02 564 985 192 163
2 2007-03 1784 4521 445 287
我正在尝试构建一个 Plotly 直方图,其中每个 stories、comments、comment_authors 和 story_authors 列有四个分类箱(x 轴),以及计数(y-轴)是特定month(即特定行)的给定数量。然后,我尝试使用 animation_frame 和 animation_group 在 Plotly Express 中根据月份对直方图进行动画处理。
例如,month=2006-10 的第一个直方图如下所示:
50 | ____
45 | | |
40 | | |
35 | | |
30 | | |
25 | | |
20 | | |
15 | | | ____
10 | | | ____ | |
5 | | | | | ______ | |
0 ----------------------------------------------------
stories comments comment_authors story_authors
在下一个动画帧的直方图中,它将从stories、comments、comment_authors、story_authors 列中读取month=2007-02 的值。
这可以在 Plotly 中构建吗?有没有比px.Histogram 更好的数字,比如px.Bar?我尝试将列放在 x 轴上并使用动画帧的月份,但这会将列堆叠到直方图上的一个 bin 中并使用整个列的计数,而不是特定行的值。
histogram = dcc.Graph(figure=px.histogram(
df, x=['stories', 'comments', 'comment_authors', 'story_authors'],
animation_frame='month', animation_group='month'
))
【问题讨论】:
标签: python pandas plotly plotly-python