有没有办法对 Bokeh 中所有子图的图形属性(例如 xlabels)进行分组?

Is there a way to group graph properties such as xlabels for all subplots in Bokeh?

我正在尝试以 Bokeh 包的列格式绘制一些子图。图的属性是相等的(xlabel、ylabel、图例位置等)。现在我必须像这样手动设置它们:

g1 = figure(plot_width=700, plot_height=450, title = 'Disp in x-direction', tools = '')
g2 = figure(plot_width=700, plot_height=450, title = 'Disp in y-direction', tools = '')

g1.legend.location = 'top_left'
g1.title.align = 'center'
g1.xaxis.axis_label = "t [s]"
g1.yaxis.axis_label = "Relative displacement [m]"
g1.toolbar.logo = None
g1.legend.click_policy="hide"
g1.legend.label_text_font_size = "8pt"

g2.legend.location = 'top_left'
g2.title.align = 'center'
g2.xaxis.axis_label = "t [s]"
g2.yaxis.axis_label = "Relative displacement [m]"
g2.toolbar.logo = None
g2.legend.click_policy="hide"
g2.legend.label_text_font_size = "8pt"

show(column(g1,g2))

数据无关。有没有办法将所有图(g1,g2.. gn)分组,以便它自动独立于图的数量?

您可以迭代数字:

for p in [g1, g2]:
    p.legend.location = 'top_left'
    p.title.align = 'center'
    ...

或者,您应该可以使用主题:https://docs.bokeh.org/en/latest/docs/reference/themes.html#bokeh.themes.Theme