I have the following piece of code to add a text box to my plot:
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)
The above piece of code runs flawlessly in one laptop while on a second one I get the following error.
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
Could anybody, please, help me in trying to solve the problem?
Note: If I comment out the render_mode='css', line the code works fine in the second system but border lines are not displayed.
Both systems are running windows 10 and bokeh is upgraded to the last available version.
Thanks.
Paolo.
The solution in bokeh 3.x is to remove the render_mode
and set the alpha value to a number different from 0 (this is invisible).
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)