有没有办法将图像放置在使用分类数据的散景图中?

时间:2019-04-17 16:26:59

标签: python python-3.x image bokeh categorical-data

我正在尝试向bokeh中的现有分类图表添加水印。我试图通过多种方法添加图像,但还无法使其正常工作。

我尝试使用类别(字符串)作为x位置值。这导致WebDriverException:

  

{“ errorMessage”:“未定义不是对象(正在评估   'document.getElementsByClassName('bk-root')[0] .children [0] .getBoundingClientRect')“,” request“:{” headers“:{” Accept“:” application / json“,” Accept-Encoding“ :“身份”,“内容长度”:“ 171”,“内容类型”:“ application / json; charset = UTF-8”,“主机”:“ 127.0.0.1:52857”,“用户代理” :“硒/3.141.0   (蟒蛇   Windows)“},” httpVersion“:” 1.1“,” method“:” POST“,” post“:” {\“ script \”:   \“ \ n返回   document.getElementsByClassName('bk-root')[0] .children [0] .getBoundingClientRect()\ n \“,   \“ args \”:[],\“ sessionId \”:   \“ 308a7240-6123-11e9-a877-6d9cf99e3c61 \”}“,” url“:” / execute“,” urlParsed“:{” anchor“:”“,” query“:”“,” file“:” execute “,”目录“:” /“,”路径“:” / execute“,”相对“:” / execute“,”端口“:”“,”主机“:”“,”密码“:”“,” user“:”“,” userInfo“:”“,” authority“:”“,” protocol“:”“,” source“:” / execute“,” queryKey“:{},” chunks“:[” execute “]},” urlOriginal“:” / session / 308a7240-6123-11e9-a877-6d9cf99e3c61 / execute“}}

我也尝试过将类别作为列表中的位置(类别[5])。这不会出错,但是不会在图上放置图像。

# Add watermark
p.image_url(url=[r'static/images/image.png'], x='Mismatch', y=500, w=100, h=100,
                anchor = 'center',
                global_alpha = 0.2)

预期结果是,图像将在我的分类图中出现在所需位置。

实际结果是没有图像出现,或者出现了webdriverexception。

谢谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您可以将此解决方法与Div一起使用。您可以使用内联CSS样式表(Bokeh v1.1.0)将任意HTML代码放在Div内,并将此Div放在屏幕上的任何位置。

from bokeh.plotting import figure, show
from bokeh.models import CustomJS, Div, Row

p1 = figure(plot_width = 300, plot_height = 300, x_range = (0, 10), y_range = (0, 10), title = "Doggy as background")
p1.line([1, 2, 3, 5, 6, 7, 8, 9, 10], [4, 5, 6, 1, 2, 3, 7, 8, 9, 0], line_width = 5)
url = "https://cdn3.iconfinder.com/data/icons/line/36/dog_head-512.png"
d1 = Div(text = '<div style="position: absolute; left:-300px; top:10px"><img src=' + url + ' style="width:280px; height:280px; opacity: 0.3"></div>')

show(Row(p1, d1))

结果:

enter image description here

相关问题