Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Bokeh服务器不适用于条形图,但适用于绘图_Python_Bokeh - Fatal编程技术网

Python Bokeh服务器不适用于条形图,但适用于绘图

Python Bokeh服务器不适用于条形图,但适用于绘图,python,bokeh,Python,Bokeh,我的bokeh服务器在本地工作,我可以使用命令运行电影示例:bokeh serve--show movies: 我创建了一个简单的脚本来显示条形图。虽然当我将其显示为静态html文件时它可以工作,如下所示,但使用bokeh serve时它不起作用: import pandas as pd from bokeh.charts import Bar, output_file, show dict_name = { 'values': { 'label_name': 44,

我的bokeh服务器在本地工作,我可以使用命令运行电影示例:bokeh serve--show movies:

我创建了一个简单的脚本来显示条形图。虽然当我将其显示为静态html文件时它可以工作,如下所示,但使用bokeh serve时它不起作用:

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

dict_name = {
    'values': {
        'label_name': 44, 
        'label_name': 28, 
        'label_name': 22,
        'label_name': 20, 
        'label_name': 15,
        'label_name': 7, 
        'label_name': 6,
        'label_name': 4, 
        'label_name': 4,
        'label_name': 2, 
    }
}
df = pd.DataFrame(dict_name)
df['label'] = df.index
p = Bar(df, values='values', label='label', legend=False, 
title='title', 
        xlabel = "", ylabel = "")

output_file("bar.html")

show(p)

在目录或文件上执行bokeh服务时,会打开一个空白页。我不确定我是否做错了什么,或者服务器是否只是没有使用条形图。不管是哪种方式,我都非常希望能找到解决方案或解决办法。谢谢。

您需要将图表添加到
curdoc
。由于您没有向文档中添加任何内容,因此当
bokeh-serve
运行脚本时,它只返回一个空白文档并显示:

from bokeh.io import curdoc
import pandas as pd
from bokeh.charts import Bar, output_file, show

dict_name = {
    'values': {
        'label_name': 44,
        'label_name': 28,
        'label_name': 22,
        'label_name': 20,
        'label_name': 15,
        'label_name': 7,
        'label_name': 6,
        'label_name': 4,
        'label_name': 4,
        'label_name': 2,
    }
}
df = pd.DataFrame(dict_name)
df['label'] = df.index
p = Bar(df, values='values', label='label', legend=False,
title='title',
        xlabel = "", ylabel = "")

# this was missing, every bokeh serve "script" example has this
curdoc().add_root(p)