【发布时间】:2019-06-06 04:09:37
【问题描述】:
我有一个具有以下格式的 .csv,我将其加载到数据框中:
version, add, subtract, divide, multiply, mod, exp
1.0, 1, 2, 3, 4, 5, 6
1.1, 1, 2, 3, 4, 5, 6
1.2, 1, 2, 3, 4, 5, 6
我格式化数据,使其在字典中:
{
'version' : [1.0, 1.2, 1.3]
'add' : [1, 1, 1]
'subtract' : [2, 2, 2]
'divide' : [3, 3, 3]
'multiply' : [4, 4, 4]
'mod' : [5, 5, 5]
'exp' : [6, 6, 6]
}
我正在尝试根据example found here 将其绘制为散景 vbar 堆栈。其中 x 轴是随时间变化的版本号,每个条形图是每个版本的每个操作的总和的堆叠条形图。
这是我的代码:
operations_df = pd.read_csv('the_csv')
# grab versions from first column
op_versions = list(operations_df.iloc[:, 0])
# grab operations from header except version
operations = list(operations_df.columns.values[1:])
data = {'op_verions': op_versions}
# loop through columns appending to dict
for col in operations_df:
data[col] = list(operations_df[col])
operations_plot = figure(x_range=op_versions, title="Operation Timings")
operations_plot.vbar_stack(operations, x='op_versions' color=Inferno[len(operations)], source=data,
legend=[value(x) for x in op_versions])
但我得到了错误:
广播的关键字参数序列的长度必须相同。得到长度:[3, 6]
我不明白不匹配的来源?每个操作和版本有 3 个值。我确信这是一个简单的解决方法,我盯着它看这么久是看不出来的。唯一有 6 个值的地方是操作数,我给出了正确的颜色数。
【问题讨论】: