在bokeh记号标签中插入换行符

2024-04-19 07:15:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Bokeh中创建多行格式的刻度标签。 在常规Python中以这种方式格式化是很简单的,例如

'{} \n{}'.format('Category', 'Percentage')

将打印

^{pr2}$

在我的代码中,我这样做是为了创建我的绘图数据:

ds = OrderedDict(sorted(subdict.items(), key=lambda v: v[1], reverse=True))
ks = [i+', {:}% '.format(str(round(j/sum(ds.values())*100, None))) for i, j in ds.items()]
data = {'kz': ks, 'vals':list(ds.values())}
source = ColumnDataSource(data=data)

如果我在上面代码的format()语句中插入一个换行符(例如', \n {:}%'),bokeh会忽略它。在

bokeh.models.printfitickformatter似乎没有提供换行符

以及

bokeh.models.CategoricalTickFormatter实际上什么都不做(方法是“pass”)

藏在bokeh文件里

https://docs.bokeh.org/en/latest/docs/reference/models/formatters.html

for DatetimeTickFormatter是语句:

%n A newline character. Bokeh text does not currently support newline characters.

我只能假设这适用于博凯语的所有文本。在

有谁能确认,纠正,或提供一个解决办法?在

注意:在我的用例中,图表只导出为png。在


Tags: 代码formatdocsfordatamodels格式bokeh