[英]I want to add two y axis values in a bokeh line plot
这行代码有什么问题..请帮助
import pandas as pd
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_file
output_file ('newfile.html')
data = pd.read_excel(r'C:\Users\ASyed\OneDrive - NKT\PythonProject\bokehPractise\newfile\19AJ100429-GC3-FR-003-A1-KP240.000-KP248.831-SL-AT.xlsx', \
sheet_name= 'Listing')
df = pd.DataFrame(data)
df.columns = [x.replace("\n", " ") for x in df.columns.to_list()]
SOURCE = ColumnDataSource(data = df)
p = figure (plot_width = 800, plot_height = 600)
p.line(x= 'KP [km]', y =[['DOL [m]'], ['DOC [m]']], source = SOURCE )
p.title.text = 'DOL Visualization'
p.xaxis.axis_label = 'Kilometer Point'
p.yaxis.axis_label = 'DOC'
show(p)
我正在使用 pandas 和散景。 我想要一个 plot,其中两条 y 轴线来自两个不同的列。 上面的代码给出了以下错误和 html 中的木板散景 plot。
Expected y to reference fields in the supplied data source.
When a 'source' argument is passed to a glyph method, values that are sequences
(like lists or arrays) must come from references to data columns in the source.
For instance, as an example:
source = ColumnDataSource(data=dict(x=a_list, y=an_array))
p.circle(x='x', y='y', source=source, ...) # pass column names and a source
Alternatively, *all* data sequences may be provided as literals as long as a
source is *not* provided:
p.circle(x=a_list, y=an_array, ...) # pass actual sequences and no source
当您使用source
作为图形的输入时,您只能添加字符串作为指向数据的指针。
在你的情况下使用
p.line(x= 'KP [km]', y ='DOL [m]', source = SOURCE )
代替
p.line(x= 'KP [km]', y =[['DOL [m]'], ['DOC [m]']], source = SOURCE )
如果要向一个图形添加多条线,请为每条线调用一次p.line()
。
import pandas as pd
from bokeh.plotting import figure, show, output_notebook
from bokeh.models import ColumnDataSource
output_notebook()
df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6]})
source = ColumnDataSource(df)
p = figure(width=300, height=300)
p.line(x='index', y='a', source=source)
p.line(x='index', y='b', source=source, color='red')
show(p)
查看官方文档中的多行示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.