Luk*_*van 10
问题是您必须指定哪个列应该是"x"列.如果未指定"x"值,则bokeh.plotting中的默认行为是尝试在ColumnDataSource中找到名为"x"的列(该列不存在).
这里有一个棘手的问题是你在pandas中使用了一个命名索引('timeseries').创建ColumnDataSource时会继承该名称,以便您的源可能如下所示:
ds = ColumnDataSource(df)
print(ds.data)
# the ts_n values would be the actual timestamps from the df
> {'timestamp': [ts_1, ts_2, ts_3, ts_4, ts_5], 'avg': [0.9, 0.8, 0.7, 0.8, 0.9]}
Run Code Online (Sandbox Code Playgroud)
如果你使用它会工作:
p.line(source=ds, x='timestamps', y='avg')
Run Code Online (Sandbox Code Playgroud)
我通常重置索引,这使索引成为一列.与丑陋的解决方案类似.然后绘制指定的列.
df.reset_index(inplace = True)
Run Code Online (Sandbox Code Playgroud)
或者你可以只引用列,在matplotlib中,它通常以你想要的方式默认使用索引.不确定它是否适合您,但值得一试.
df["avg"].plot()
Run Code Online (Sandbox Code Playgroud)
或者你可以尝试时间序列图方法吗?详情如下.
| 归档时间: |
|
| 查看次数: |
10156 次 |
| 最近记录: |