2017-04-03 51 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’.

只需按照最新文档中给出的示例,就不会遇到同样的问题。