简体   繁体   English

更改bokeh图中选项卡的样式

[英]Change style of tabs in bokeh plot

I would like to know if there is a way to change the properties of tabs produced on a bokeh plot. 我想知道是否可以更改散景图上产生的选项卡的属性。 Changes like increasing the text font, changing the tab width and so on. 诸如增加文本字体,更改标签宽度等更改。 The following is a simple code for producing a plot with two tabs. 以下是用于生成具有两个选项卡的绘图的简单代码。

from bokeh.models.widgets import Panel, Tabs
from bokeh.io import output_file, show
from bokeh.plotting import figure

output_file("slider.html")

p1 = figure(plot_width=300, plot_height=300)
p1.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
tab1 = Panel(child=p1, title="circle")

p2 = figure(plot_width=300, plot_height=300)
p2.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=3, color="navy", alpha=0.5)
tab2 = Panel(child=p2, title="line")

tabs = Tabs(tabs=[ tab1, tab2 ])

show(tabs)

You can override the default Bokeh tabs styles like shown below (works for Bokeh v1.1.0). 您可以覆盖如下所示的默认“散景”标签样式(适用于Bokeh v1.1.0)。

Please note that Bokeh CSS library implementation may change in upcoming versions. 请注意,Bokeh CSS库的实现可能会在以后的版本中更改。

The css styles found below will work for v1.1.0 but are not backwards compatible with v1.0.4 以下找到的css样式适用于v1.1.0,但与v1.0.4向后兼容

from bokeh.plotting import save, figure
from bokeh.models import Paragraph, Panel, Tabs, Column

template = """
{% block postamble %}
<style>
.bk-root .bk-tab {
    background-color: cyan;
    width: 200px;
    color: red;
    font-style: italic;
}

.bk-root .bk-tabs-header .bk-tab.bk-active{
background-color: yellow;
color: blue;
font-style: normal;
font-weight: bold;
}

.bk-root .bk-tabs-header .bk-tab:hover{
background-color: yellow
}

</style>
{% endblock %}
"""

p = Paragraph(text = "Another tab", width = 600)

plot = figure()
plot.line(x = [1, 2], y = [3, 4])
tabs = [Panel(title = 'Tab1', child = plot)]
tabs.append(Panel(title = 'Tab2', child = p))

save(Column(Tabs(tabs = tabs, width = 600)), template = template)

Result: 结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM