[英]Bokeh: ploting multiple separate lines
ISSUE no.1: 问题1:
I cant come up with solving the way how to plot multiple separate lines other than this piece: 我无法提出解决方法来绘制除这部分以外的多条单独的线:
main_time_line = p.line(x=(start, stop), y=(0, 0))
g1 = p.square(source=source, x='examination__date', y=0, size=4,
color='black', name='g1')
hover_tool.renderers.append(g1)
g2 = p.circle(source=source, x='examination__date', y='level', size=15)
for i, (idate, ilevel, iname) in enumerate(zip(source.data['examination__date'],
source.data['level'],
source.data['examination__name'])):
vert = 'top' if ilevel < 0 else 'bottom'
horizontal = 'right' if ilevel < 0 else 'left'
yoff = -10 if ilevel < 0 else 10
p.line(x=idate, y=(0, ilevel), color='black', line_width=3)
my_txt = Label(x=idate,
y=ilevel,
text=iname,
text_align=horizontal,
text_baseline=vert,
text_font_size='13px',
y_offset=yoff)
p.add_layout(my_txt)
The result of the above is: 上面的结果是:
The visual effect is more or less what I inteded, however the fact that vertical lines are ploted using for-loop, creates problems with widgets, namely: checkboxes react only to square and circle. 视觉效果或多或少是我所想要的,但是使用for循环绘制垂直线这一事实会给小部件带来问题,即:复选框仅对正方形和圆形起作用。
I guess its due to the fact that vert lines are ploted without source arg, therefore emiting changes via JS callback doesnt update data for them (source is a ColumDataSource from pandas dataframe) I wasn't able to plot them the way they are while using source arg. 我猜是由于没有源arg才绘制了垂直线,因此通过JS回调发出更改不会更新它们的数据(源是来自pandas数据帧的ColumDataSource),我无法按照使用时的方式绘制它们源arg。
ISSUE no.2: assuming that i scrap the for-loop, Im unable to operate placement of text 问题2:假设我取消了for循环,我无法操作文本的放置
Any suggestions please ? 有什么建议吗?
Further inspection of the documentation led me discovering segments and LabelSets, therefore to achieve the effect i wanted, i only had to add a 'zeroes' list consisting of 0 to ColumnDataSource. 对文档的进一步检查使我发现了段和LabelSet,因此要实现我想要的效果,我只需要向ColumnDataSource添加一个由0组成的“零”列表。
Im sure there are many other ways to handle it tho. 我肯定还有很多其他方法可以处理它。
main_time_line = p.line(x=(start, stop), y=(0, 0), color='blue')
g1 = p.square(source=source, x='examination__date', y=0, size=4,
color='black', name='g1')
hover_tool.renderers.append(g1)
g2 = p.circle(source=source, x='examination__date', y='level', size=15)
g3 = p.segment(source=source,
x0='examination__date',
y0='zeroes',
x1='examination__date',
y1='level',
color="#F4A582",
line_width=3)
labels = LabelSet(x='examination__date', y='level', text='examination__name',
level='glyph', x_offset=5, y_offset=5, source=source,
render_mode='canvas')
p.add_layout(labels)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.