我有以下数据帧:
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
我试图构建一个绘图直方图,其中有四个分类箱(x轴),分别对应于stories
、comments
、comment_authors
和story_authors
列,计数(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轴上,并使用月份作为动画帧,但这会将列堆叠到直方图上的一个箱子中,并使用整个列的计数,而不是特定行的值
histogram = dcc.Graph(figure=px.histogram(
df, x=['stories', 'comments', 'comment_authors', 'story_authors'],
animation_frame='month', animation_group='month'
))
@r-初学者的答案是最好的方法,但我想与大家分享如何手动操作,以防将来有人发现这个问题(这样我的辛劳就不会白费了)。下面是在@r-初学者回答之前我是如何手动完成的
不可能用您呈现的数据绘制直方图。你能做的最好的是一个条形图,你可以用一个时间序列来制作它的动画。我已经修改了官方reference中的样本以适合您的数据
相关问题 更多 >
编程相关推荐