2017-04-03 27 views
1

我有一個定義的值字典,其中key是一個字符串形式的日期,值是一個浮點數組。將字典值繪製成多行/時間序列散景圖

解釋是這樣的:

dict = 
{'2017-03-23': [1.07874, 1.07930, 1.07917, 1.07864,], 
'2017-03-27': [1.08382, 1.08392, 1.08410, 1.08454], 
'2017-03-24': [1.07772, 1.07721, 1.07722, 1.07668]} 

我要顯示的每個日期在背景虛化line_chart一個單獨的行。由於日期間隔會隨時間而改變,因此我不想簡單地爲每個日期定義p1.line,p2.line,p3.line(靜態設置),因爲繪製日期的數量會隨時間而變化。

我試圖按照這裏的教程︰http://bokeh.pydata.org/en/0.9.3/docs/user_guide/charts.html但我一直在掙扎,並得到錯誤。

這裏是我的代碼:

#input dates at this occasion 
dates = ['2017-03-27','2017-03-24', '2017-03-23'] 

#dataframe is taken from input and contains columns date,time,close and other columns that I am not using 
df 

#I create a dictionary of dataframe in the structure described above 
dict = {k: list(v) for k, v in df.groupby("date")["close"]} 

#i want to plot chart 
output_file("chart2.html") 
p = figure(title="Dates line charts", x_axis_label='Index', y_axis_label='Price') 
p = TimeSeries(dict, index='Index', legend=True, title="FX", ylabel='Price Prices') 
show(p) 

我收到此錯誤:

AttributeError錯誤:意外屬性 '指標' 到圖表,可能的屬性之上,background_fill_alpha,background_fill_color,下面,border_fill_alpha, border_fill_color,css_classes,disabled,extra_x_ranges,extra_y_ranges,h_symmetry,height,hidpi,inner_height,inner_width,js_callbacks,left,lod_factor,lod_interval,lod_threshold,lod_timeout,min_border,min_border_bottom,min_border_left,min_border_right,min_border_top,name,outline_line_alpha,outl標題,標題_位置,工具_事件,工具欄,toolbar_location,toolbar_sticky,v_symmetry,webgl,寬度,x_mapper_type,x_range,xlabel,xscale,x_label,line_line_dat,outline_line_color,outline_line_dash,outline_line_dash_offset,outline_line_join,outline_line_width,plot_height,plot_width,renderer,right,sizing_mode, y_mapper_type,y_range,ylabel或yscale

感謝您的幫助。

回答

0

您正在查看非常古老的文檔(0.9.3)。最新的文檔(0.12.4)爲散景時間序列can be found here。如您所見,Timeseries不再接受index參數。可用的參數是

data (list(list), numpy.ndarray, pandas.DataFrame, list(pd.Series)) – a 2d data source with columns of data for each stepped line.

x (str or list(str), optional) – specifies variable(s) to use for x axis

y (str or list(str), optional) – specifies variable(s) to use for y axis

builder_type (str or Builder, optional) – the type of builder to use to produce the renderers. Supported options are ‘line’, ‘step’, or ‘point’.

只需按照最新文檔中給出的示例,就不會遇到同樣的問題。