下面是一个简单的情节示例,其中有一些带有长标签的分类轴。
from bokeh.plotting import figure, show
x_labs = [
"Long Tick Label That Needs Line Breaks",
"Longer Tick Label That Needs Line Breaks",
"Even Longer Tick Label That Needs Line Breaks"
]
y_labs = ["foo", "bar", "baz"]
x = [x_lab for __ in range(len(x_labs)) for x_lab in x_labs]
y = ["foo", "foo", "foo", "bar", "bar", "bar", "baz", "baz", "baz"]
colors = [
"#0B486B", "#79BD9A", "#CFF09E",
"#79BD9A", "#0B486B", "#79BD9A",
"#CFF09E", "#79BD9A", "#0B486B"
]
p = figure(x_range=x_labs, y_range=y_labs)
p.rect(x, y, color=colors, width=1, height=1)
show(p)
x轴标签重叠,所以我想插入换行符。我无法弄清楚如何做到这一点。我尝试在单词之间添加'\n'
,'\\n'
,'<br>'
但是没有效果。
我有理由不想将标签更改为较短的字符串,增加字形大小,旋转轴标签或使用其他绘图包。所以,我真的只是想知道我是否可以在散景中为标签添加换行符。
我正在使用散景版0.10.0。
非常感谢。
答案 0 :(得分:-1)
基于DOS的系统中的换行符是Ascii 13,10
这可以用序列\r\n