如何在bokeh中创建多线图标题? [英] How to create a multi-line plot title in bokeh?

查看:169
本文介绍了如何在bokeh中创建多线图标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在bokeh中创建多行图标题?...与 https://github.com/bokeh/bokeh/issues/994
这个解决了吗?

How do you create a multiline plot title in bokeh?... same question as https://github.com/bokeh/bokeh/issues/994
Is this resolved yet?

import bokeh.plotting as plt

plt.output_file("test.html")
plt.text(x=[1,2,3], y = [0,0,0], text=['hello\nworld!', 'hello\nworld!', 'hello\nworld!'], angle = 0)
plt.show()

另外,标题文本字符串可以接受格式文本吗?

Additionally, can the title text string accept rich text?

推荐答案

在Bokeh的最新版本中,标签和文本字形可以接受文本中的换行符,并且这些换行符将按预期方式呈现.对于多行标题,您必须为所需的每一行添加显式的Title批注.这是一个完整的示例:

In recent versions of Bokeh, labels and text glyphs can accept newlines in the text, and these will be rendered as expected. For multi-line titles, you will have to add explicit Title annotations for each line you want. Here is a complete example:

from bokeh.io import output_file, show
from bokeh.models import Title
from bokeh.plotting import figure

output_file("test.html")

p = figure(x_range=(0, 5))
p.text(x=[1,2,3], y = [0,0,0], text=['hello\nworld!', 'hello\nworld!', 'hello\nworld!'], angle = 0)

p.add_layout(Title(text="Sub-Title", text_font_style="italic"), 'above')
p.add_layout(Title(text="Title", text_font_size="16pt"), 'above')

show(p)

哪个会产生:

请注意,由于基础HTML画布不接受富文本格式,因此您只能使用Bokeh公开的标准文本属性".如果您需要类似的内容,可以使用自定义扩展名

Note that you are limited to the standard "text properties" that Bokeh exposes, since the underlying HTML Canvas does not accept rich text. If you need something like that it might be possible with a custom extension

这篇关于如何在bokeh中创建多线图标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆