且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改bokeh图中选项卡的样式

更新时间:2023-01-28 22:17:07

您可以覆盖如下所示的默认Bokeh标签样式(适用于Bokeh v1.1.0).

You can override the default Bokeh tabs styles like shown below (works for Bokeh v1.1.0).

请注意,Bokeh CSS库的实现可能会在即将发布的版本.

Please note that Bokeh CSS library implementation may change in upcoming versions.

下面找到的css样式适用于v1.1.0,但向后兼容v1.0.4

The css styles found below will work for v1.1.0 but are not backwards compatible with 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)

结果: