bokeh - 如何在散景图中的同一行上放置多个注释?
问题描述
所以我正在制作一些散景图,我想在绘图区域之外添加一些文本。假设我想将一个注释放在右上角上方,另一个放在左上角上方。我遇到的问题是散景将这两个注释垂直堆叠,但我希望它们水平位于同一条线上。有没有办法做到这一点?
代码:
from bokeh.plotting import figure
from bokeh.models import Legend
plot = figure(**plot_params)
date_label = Legend(items=[('label1', [])], location='center_left', border_line_color=None, margin=0)
plot.add_layout(date_label, 'above')
resource_label = Legend(items=[('label2', [])], location='center_right', border_line_color=None, margin=0)
plot.add_layout(resource_label, 'above')
解决方案
您可以使用min_border
属性来扩展绘图尺寸,并Label
通过使用并设置为单位render_mode=css
来在任意位置添加注释。x
y
screen
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import Label
output_notebook()
p = figure(plot_width=400, plot_height=400)
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
p.border_fill_color = "whitesmoke"
p.min_border = 50
top_left_label = Label(
x=-35, y=320, x_units='screen', y_units='screen',
text='Top Left Label', render_mode='css', background_fill_color='white')
bottom_right_label = Label(
x=200, y=-45, x_units='screen', y_units='screen',
text='Bottom Right Label', render_mode='css', background_fill_color='white')
p.add_layout(top_left_label)
p.add_layout(bottom_right_label)
show(p)
来自文档的注释:
CSS 标签不会出现在使用“保存”工具的输出中。
推荐阅读
- python - Pylint:“导入模块时出现问题......:无法导入名称‘类型’”
- c# - 如何在 WCF 中更改命名空间和前缀
- java - 冰雹序列,递归,缺少1个案例
- github - 为什么我的 VS Code 提交看起来像是为 Github 中的任何其他人提交的?
- php - Prestashop 折扣以增加购物车总价
- apache-spark - 使用 spark submit 在 Spark Cluster 上提交应用程序
- java - 具有基本身份验证的 JAX-WS 请求
- jquery - 更改当前页面链接的样式在索引页面上不起作用
- marklogic - 各种日期格式的范围索引
- javascript - 事件侦听器未正确链接到我的元素