属性错误:TimeSeries Bokeh Library

时间:2016-03-31 09:37:19

标签: python bokeh

这是从散景文档中选取的示例。 它显示属性错误。 我在anaconda环境中使用ipython。

import pandas as pd
from bokeh.charts import TimeSeries, output_file, show

AAPL = pd.read_csv(
        "http://ichart.yahoo.com/table.csv?s=AAPL&a=0&b=1&c=2000&d=0&e=1&f=2010",
        parse_dates=['Date'])

output_file("timeseries.html")

data = dict(AAPL=AAPL['Adj Close'], Date=AAPL['Date'])

p = TimeSeries(data, index='Date', title="APPL", ylabel='Stock Prices')

show(p)


AttributeError                            Traceback (most recent call last)
<ipython-input-3-fe34a9860ab7> in <module>()
     10 data = dict(AAPL=AAPL['Adj Close'], Date=AAPL['Date'])
     11 
---> 12 p = TimeSeries(data, index='Date', title="APPL", ylabel='Stock Prices')
     13 
     14 show(p)

C:\Users\Bhaskara\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\charts\builders\timeseries_builder.py in TimeSeries(data, x, y, builder_type, **kws)
    100     kws['x'] = x
    101     kws['y'] = y
--> 102     return create_and_build(builder_type, data, **kws)

C:\Users\Bhaskara\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\charts\builder.py in create_and_build(builder_class, *data, **kws)
     64     # create a chart to return, since there isn't one already
     65     chart_kws = { k:v for k,v in kws.items() if k not in builder_props}
---> 66     chart = Chart(**chart_kws)
     67     chart.add_builder(builder)
     68     chart.start_plot()

C:\Users\Bhaskara\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\charts\chart.py in __init__(self, *args, **kwargs)
    123         # supported types
    124         tools = kwargs.pop('tools', None)
--> 125         super(Chart, self).__init__(*args, **kwargs)
    126         defaults.apply(self)
    127         if tools is not None:

C:\Users\Bhaskara\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\models\plots.py in __init__(self, **kwargs)
     76             raise ValueError("Conflicting properties set on plot: background_fill, background_fill_color.")
     77 
---> 78         super(Plot, self).__init__(**kwargs)
     79 
     80     def select(self, *args, **kwargs):

C:\Users\Bhaskara\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\model.py in __init__(self, **kwargs)
     75         self._id = kwargs.pop("id", make_id())
     76         self._document = None
---> 77         super(Model, self).__init__(**kwargs)
     78         default_theme.apply_to_model(self)
     79 

C:\Users\Bhaskara\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\core\properties.py in __init__(self, **properties)
    699 
    700         for name, value in properties.items():
--> 701             setattr(self, name, value)
    702 
    703     def __setattr__(self, name, value):

C:\Users\Bhaskara\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\core\properties.py in __setattr__(self, name, value)
    720 
    721             raise AttributeError("unexpected attribute '%s' to %s, %s attributes are %s" %
--> 722                 (name, self.__class__.__name__, text, nice_join(matches)))
    723 
    724     def set_from_json(self, name, json, models=None):

AttributeError: unexpected attribute 'index' to Chart, possible attributes are above, background_fill_alpha, background_fill_color, below, border_fill_alpha, border_fill_color, disabled, extra_x_ranges, extra_y_ranges, h_symmetry, height, hidpi, left, legend, lod_factor, lod_interval, lod_threshold, lod_timeout, logo, min_border, min_border_bottom, min_border_left, min_border_right, min_border_top, name, outline_line_alpha, outline_line_cap, outline_line_color, outline_line_dash, outline_line_dash_offset, outline_line_join, outline_line_width, plot_height, plot_width, renderers, responsive, right, tags, title, title_standoff, title_text_align, title_text_alpha, title_text_baseline, title_text_color, title_text_font, title_text_font_size, title_text_font_style, tool_events, toolbar_location, tools, v_symmetry, webgl, width, x_mapper_type, x_range, xgrid, xlabel, xscale, y_mapper_type, y_range, ygrid, ylabel or yscale

2 个答案:

答案 0 :(得分:1)

而不是使用属性索引,设置x =&#39;日期&#39;。

p = TimeSeries(data, x ='Date', title="APPL", ylabel='Stock Prices')

答案 1 :(得分:0)

检查您使用的是哪个版本,如果您使用的是0.11.1,则可以使用 http://bokeh.pydata.org/en/0.11.1/docs/user_guide/plotting.html也是这样做的。