Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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 hbar示例_Python_Bokeh - Fatal编程技术网

Python 分类值为白色框的bokeh hbar示例

Python 分类值为白色框的bokeh hbar示例,python,bokeh,Python,Bokeh,我有一个简单的hbar图的代码,它被精简为我认为应该是的,但显示为一个白框。我可以得到一个简单的线图示例,这样我就知道标题设置正确了 from bokeh.embed import components from bokeh.plotting import figure fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries'] cou

我有一个简单的hbar图的代码,它被精简为我认为应该是的,但显示为一个白框。我可以得到一个简单的线图示例,这样我就知道标题设置正确了

        from bokeh.embed import components
        from bokeh.plotting import figure

        fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
        counts = [5, 3, 4, 2, 4, 6]

        p = figure(plot_height=250, title="Fruit counts",
                   toolbar_location=None, tools="")

        p.hbar(y=fruits, right=counts)

        data, div = components(p)
控制台中的错误是[Bokeh]无法设置初始范围 如果有人能告诉我需要添加哪些有用的文档。

既然如此,您需要为您的y_范围指定一个FactorRange。这可以通过p.y_range=FactorRangefactors=fruits或其速记版本p.x_range=fruits来完成。 以下示例正确显示了该图:

from bokeh.embed import components
from bokeh.plotting import figure, show
from bokeh.models import FactorRange

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]

p = figure(y_range=FactorRange(factors=fruits), plot_height=250, title="Fruit counts",
            toolbar_location=None, tools="")

p.hbar(y=fruits, right=counts)

show(p)
现在,您需要为您的y_范围指定一个FactorRange。这可以通过p.y_range=FactorRangefactors=fruits或其速记版本p.x_range=fruits来完成。 以下示例正确显示了该图:

from bokeh.embed import components
from bokeh.plotting import figure, show
from bokeh.models import FactorRange

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]

p = figure(y_range=FactorRange(factors=fruits), plot_height=250, title="Fruit counts",
            toolbar_location=None, tools="")

p.hbar(y=fruits, right=counts)

show(p)

仅供参考,但在大多数情况下,您可以通过列表,例如y_range=[‘苹果’、‘梨’、‘油桃’、‘李子’、‘葡萄’、‘草莓’]就足够了。仅供参考,但在大多数情况下,您可以通过列表,例如y_range=[‘苹果’、‘梨’、‘油桃’、‘李子’、‘葡萄’、‘草莓’]就足够了。