首页 > 解决方案 > Bokeh Circle 半径不接受浮点数

问题描述

我想绘制具有特定半径的圆形标记。用整数绘制这些圆形标记效果很好。

cavity_glyph = Circle(
            x='x_coordinate',
            y='y_coordinate',
            radius=1.,
            radius_dimension='max',
            radius_units='data',
            line_color='cavity_color'
        )

但是,当我为半径输入浮点数时,没有绘制任何内容

cavity_glyph = Circle(
            x='x_coordinate',
            y='y_coordinate',
            radius=0.5,
            radius_dimension='max',
            radius_units='data',
            line_color='cavity_color'
        )

我通读了散景参考资料,但找不到解决方案。

我期望半径为 0.5 的圆圈,而不是空地

标签: pythonpython-3.xbokeh

解决方案


我无法用您的示例重现您的错误。检查您的 Bokeh 版本可能很有用,它可能是一个已在较新版本中修复的错误 ( bokeh -v)。这是一个使用 Bokeh 1.2.0 测试的工作示例:

from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource
from bokeh.models.markers import Circle

output_file("line.html")

p = figure(plot_width=800, plot_height=800)

data = {'x': [1, 2, 3, 4, 5], 'y': [5, 6, 7, 8, 9], 'radius': [0.1, 0.3, 0.5, 0.7, 0.9]}
source = ColumnDataSource(data)

data2 = {'x': [1, 2, 3, 4, 5], 'y': [9, 8, 7, 6, 5], 'radius': [0.1, 0.3, 0.5, 0.7, 0.9]}
source2 = ColumnDataSource(data2)

p.circle(x='x', y='y', radius='radius', color='navy', alpha=0.5, source=source)

cavity_glyph = Circle(
            x='x',
            y='y',
            radius='radius',
            fill_color='red',
            fill_alpha=0.5,
            radius_dimension='max',
            radius_units='data'
        )

p.add_glyph(source2, cavity_glyph)

show(p)

在此处输入图像描述


推荐阅读