I got a issue similar to the following one : Creating a multiline graph using Vincent, but I did'nt find the solution.
我遇到了类似下面的问题:使用Vincent创建一个多线图,但我找不到解决方案。
I want to display a multiline graph to get the number of discussions processed by users, on a chat tool, for each hour of the day.
I got a DataFrame with the following format below. The left column represents the hours, and each other column the number of discussions by user for each hour :
我想显示一个多线图,以获取用户在聊天工具上为当天的每个小时处理的讨论数量。我有一个DataFrame,格式如下。左列表示小时数,左列表示用户每小时的讨论数:
user1 user2
... ... ...
8 0 0
9 1 0
10 0 0
11 0 0
12 11 0
... ... ...
Note : I didn't display all the DF but I got rows from 0 to 23.
注意:我没有显示所有DF但是我从0到23获得了行。
I tried the following code to build my graph :
我尝试了以下代码来构建我的图:
graph = vincent.Line(df)
graph.axis_titles(x='Hour', y='Number of discussions')
graph.legend(title="Users")
Which gave me the following error :
这给了我以下错误:
array is not broadcastable to correct shape
I did't really get what's wrong, I tried something else. I copied my index as a serie in my DF, what gave me the following format :
我没有弄到什么问题,我尝试了别的东西。我在我的DF中将我的索引复制为系列,这给了我以下格式:
user1 user2 hour
... ... ... ...
8 0 0 8
9 1 0 9
10 0 0 10
11 0 0 11
12 11 0 12
... ... ... ...
And I tried the following code :
我尝试了以下代码:
graph = vincent.Line(df, iter_idx='hour')
graph.axis_titles(x='Hour', y='Number of discussions')
graph.legend(title="Users")
Here, I got no error, but like davidheller in the post I linked, I got a graph without any line, and just the value 0 in absicssa. I guess my parameters for the vincent.Line object are not correct, but I don't see how to pass them. Do you have any idea ?
在这里,我没有错误,但像我链接的帖子中的davidheller,我得到了一个没有任何行的图表,只有absicssa中的值0。我想我的vincent.Line对象的参数不正确,但我不知道如何传递它们。你有什么主意吗 ?
1 个解决方案
#1
0
I got the same problem, what I winded up doing was creating a dictionary instead of the data frame.
我遇到了同样的问题,我所做的就是创建一个字典而不是数据框。
user_d = {}
for col in list(df.columns):
user_d[col] = list(df[col])
user_d['index'] = df.index.tolist()
graph = vincent.Line(user_d, iter_idx='hour')
graph.axis_titles(x='Hour', y='Number of discussions')
graph.legend(title="Users")
Hope this helps!
希望这可以帮助!
#1
0
I got the same problem, what I winded up doing was creating a dictionary instead of the data frame.
我遇到了同样的问题,我所做的就是创建一个字典而不是数据框。
user_d = {}
for col in list(df.columns):
user_d[col] = list(df[col])
user_d['index'] = df.index.tolist()
graph = vincent.Line(user_d, iter_idx='hour')
graph.axis_titles(x='Hour', y='Number of discussions')
graph.legend(title="Users")
Hope this helps!
希望这可以帮助!