-1

我仍在学习 iPython Notebook/Jupyter 以及如何使用 Bokeh 绘图。我正在使用这里的模型步骤:http: //nbviewer.ipython.org/github/bokeh/bokeh-notebooks/blob/master/tutorial/00%20-%20intro.ipynb# 但是我的代码在 In[ 上失败了13]:在他们的例子中。从散景它说:

In [13]:

from bokeh.models import Circle, HoverTool
from bokeh.palettes import Spectral6

renderer_source = ColumnDataSource(bubble_plot.get_1964_data())

def add_circles(plot):
    plot = add_text(plot)
    # Add the circle
    circle_glyph = Circle(
        x='fertility', y='life', size='population',
        fill_color='region_color', fill_alpha=0.8,
        line_color='#7c7e71', line_width=0.5, line_alpha=0.5)
    circle_renderer = plot.add_glyph(renderer_source, circle_glyph)

    # Add the hover (only against the circle and not other plot elements)
    tooltips = "@index"
    plot.add_tools(HoverTool(tooltips=tooltips, renderers=[circle_renderer]))
    return plot

show(add_circles(get_plot()))

我的代码在第二步开始时失败。它如下,因为我使用的是我自己的数据:

In [96]:

from bokeh.models import Circle, HoverTool

from bokeh.palettes import Spectral6

from bokeh.plotting import *

In [97]:

renderer_source = ColumnDataSource(bubble_plot.get_df())

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-97-8659183dfef3> in <module>()
----> 1 renderer_source = ColumnDataSource(bubble_plot.get_df())

NameError: name 'bubble_plot' is not defined

为什么bubble_plot未定义,我该如何更改?这与他们的示例完全相同。到目前为止没有问题。谢谢!

4

1 回答 1

0

bubble_plot在单独的 python 模块中定义。您可以在笔记本顶部看到,它确实import bubble_plot加载了其他模块。你可以在这里看到内容:

https://github.com/bokeh/bokeh-notebooks/blob/master/tutorial/bubble_plot.py

于 2015-07-27T23:13:12.130 回答