如何在保留行间隙的同时在散景中显示文本

How To Display Text in Bokeh While Preserving Line Gaps

我正在尝试使用 Bokeh 2.0.1 生成包含图表和一些文本的报告,并且我正在尝试保留我输入 bokeh.layouts.gridplot.[=12 的文本中的原始行间距=]

但是,我看到在生成 HTML 文件后,所有的行间距都被删除了,基本上,所有段落都合并为一个连续的句子。我不确定为什么会这样。关于这个问题,我在 Bokeh 文档中找不到太多帮助。

这是我尝试开始工作的代码部分的最小示例。

from bokeh.layouts import gridplot
from bokeh.models import Paragraph
from bokeh.plotting import output_file, save

sampText = "PARAGRAPH 1: This is a minimal example of a text. This is a minimal example of a text. This is a minimal example of a text. This is a minimal example of a text. This is a minimal example of a text. This is a minimal example of a text.\n

PARAGRAPH 2: This is a minimal example of a text. This is a minimal example of a text. This is a minimal example of a text. This is a minimal example of a text. This is a minimal example of a text."

fig1 = ...

fig2 = ...

text = Paragraph(text = sampText, width = 1500, height_policy = "auto", style = {'fontsize': '10pt', 'color': 'black', 'font-family': 'arial'})

output_file(filename = "myMinimalExampleOutput" + ".html")
output = gridplot([fig1, fig2, text], ncols = 1, plot_width = 1500, sizing_mode = 'scale_width')
save(output)

有人能指出为什么会这样吗?

这就是 HTML 的工作原理 - 它从文本中删除所有 "unnecessary" 空格。

为了使您的两个段落生效,您必须将它们分别包装在 <p></p> 中。但由于 Paragraph 生成相同的标签,您不能使用 class。使用常规 Div 并将其 text 输入参数设置为要呈现的 HTML。

Div(text='<p>paragraph 1</p><p>paragraph 2</p>')