[英]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.