为什么散景标签选项 render_mode='css' 在一个系统上有效,但在第二个系统上返回错误?

问题描述 投票:0回答:1

我有以下代码可以将文本框添加到我的图中:

citation = bokeh.models.Label(x=xPosition, y=yPosition, x_units='screen', y_units='screen',
                 text=textstr, 
                 render_mode='css',
                 border_line_color='wheat', border_line_alpha=0,
                 background_fill_color='wheat', background_fill_alpha=0)

p.add_layout(citation)

上面的代码在一台笔记本电脑上完美运行,而在第二台笔记本电脑上我收到以下错误。

AttributeError                            Traceback (most recent call last)
Cell In[58], line 80
     74 p.line('distance', 'grade', name='Grade', color="blue", line_width=0.30, 
     75        y_range_name='Grade', line_dash="4 2", source=source)
     78 #labels = LabelSet(x='weight', y='height', text='names',
     79 #              x_offset=5, y_offset=5, source=source, render_mode='canvas')
---> 80 citation = bokeh.models.Label(x=xPosition, y=yPosition, x_units='screen', y_units='screen',
     81                  text=textstr, 
     82                  render_mode='css',
     83                  border_line_color='wheat', border_line_alpha=0,
     84                  background_fill_color='wheat', background_fill_alpha=0)
     86 p.add_layout(citation)
     89 # show the results

File C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\annotations\labels.py:122, in Label.__init__(self, *args, **kwargs)
    121 def __init__(self, *args, **kwargs) -> None:
--> 122     super().__init__(*args, **kwargs)

File C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\annotations\labels.py:78, in TextAnnotation.__init__(self, *args, **kwargs)
     77 def __init__(self, *args, **kwargs) -> None:
---> 78     super().__init__(*args, **kwargs)

File C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\annotations\annotation.py:49, in Annotation.__init__(self, *args, **kwargs)
     48 def __init__(self, *args, **kwargs) -> None:
---> 49     super().__init__(*args, **kwargs)

File C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\renderers\renderer.py:76, in Renderer.__init__(self, *args, **kwargs)
     75 def __init__(self, *args, **kwargs) -> None:
---> 76     super().__init__(*args, **kwargs)

File C:\ProgramData\Anaconda3\lib\site-packages\bokeh\model\model.py:110, in Model.__init__(self, *args, **kwargs)
    107 if "id" in kwargs:
    108     raise ValueError("initializing 'id' is not allowed")
--> 110 super().__init__(**kwargs)
    111 default_theme.apply_to_model(self)

File C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\has_props.py:298, in HasProps.__init__(self, **properties)
    296     if value is Undefined or value is Intrinsic:
    297         continue
--> 298     setattr(self, name, value)
    300 for name in self.properties() - set(properties.keys()):
    301     desc = self.lookup(name)

File C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\has_props.py:333, in HasProps.__setattr__(self, name, value)
    330 if isinstance(descriptor, property): # Python property
    331     return super().__setattr__(name, value)
--> 333 self._raise_attribute_error_with_matches(name, properties)

File C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\has_props.py:368, in HasProps._raise_attribute_error_with_matches(self, name, properties)
    365 if not matches:
    366     matches, text = sorted(properties), "possible"
--> 368 raise AttributeError(f"unexpected attribute {name!r} to {self.__class__.__name__}, {text} attributes are {nice_join(matches)}")

AttributeError: unexpected attribute 'render_mode' to Label, possible attributes are angle, angle_units, background_fill_alpha, background_fill_color, border_line_alpha, border_line_cap, border_line_color, border_line_dash, border_line_dash_offset, border_line_join, border_line_width, coordinates, group, js_event_callbacks, js_property_callbacks, level, name, propagate_hover, subscribed_events, syncable, tags, text, text_align, text_alpha, text_baseline, text_color, text_font, text_font_size, text_font_style, text_line_height, text_outline_color, visible, x, x_offset, x_range_name, x_units, y, y_offset, y_range_name or y_units

有人可以帮我解决这个问题吗?

注意:如果我注释掉 render_mode='css',则代码在第二个系统中可以正常工作,但不会显示边框线。

两个系统都运行 Windows 10,并且散景已升级到最新可用版本。

谢谢。
保罗。

python label bokeh
1个回答
0
投票

bokeh 3.x 中的解决方案是删除

render_mode
并将 alpha 值设置为不同于 0 的数字(这是不可见的)。

from bokeh.models import Label
from bokeh.plotting import figure, show, output_notebook
output_notebook()

p = figure(width=300, height=250)
p.line([1,2,3],[0,1,2])
citation = Label(
    x=1, y=1, x_units='screen', y_units='screen',
    text='Text',
    border_line_color='wheat',
    background_fill_color='wheat'
)
p.add_layout(citation)
show(p)

© www.soinside.com 2019 - 2024. All rights reserved.