2016-09-23 35 views

回答

-1

您可以添加一个简单的标题到您的情节与此:

from bokeh.plotting import figure, show, output_file 

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

enter image description here


附录

这里是绘制大熊猫数据帧为您的工作示例复制/粘贴到jupyter笔记本。它既不优雅也不pythonic。我很久以前从各种SO帖子中得到它。对不起,我不记得哪些了,所以我不能引用它们。

代码

# coding: utf-8 
from bokeh.plotting import figure, show 
from bokeh.io import output_notebook 
import pandas as pd 
import numpy as np 


# Create some data 
np_arr = np.array([[1,1,1], [2,2,2], [3,3,3], [4,4,4]]) 
pd_df = pd.DataFrame(data=np_arr) 
pd_df 

# Convert for multi-line plotting 
data = [row[1].as_matrix() for row in pd_df.iterrows()] 
num_lines = len(pd_df) 
cols = [pd_df.columns.values] * num_lines 
data 

# Init bokeh output for jupyter notebook - Adjust this to your needs 
output_notebook() 

# Plot 
p = figure(plot_width=600, plot_height=300) 
p.multi_line(xs=cols, ys=data) 
show(p) 

情节

enter image description here

+1

问题要求输入多行标题。 – PJW

0

在最新版本的背景虚化,标签和文字的字形可以接受的文本换行,并预期这些将呈现。对于多行标题,您必须为每一行添加明确的Title注释。下面是一个完整的例子:

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) 

主要生产:

enter image description here

请注意,您被限制为标准的“文本属性”即散景暴露,因为底层的HTML画布不接受富文本。如果您需要类似的东西,可能需要使用custom extension