python - Is there a way to group graph properties such as xlabels for all subplots in Bokeh?
问题描述
I am trying to plot some subplots in the column format of the Bokeh package. The properties of the graphs are equal (xlabel, ylabel, legend location etc.). Now I have to set them manually like this:
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))
The data is irrelevant. Is there a way to group all graphs (g1, g2.. gn) so that it goes automatically independent on the number of graphs?
解决方案
You can just iterate over the figures:
for p in [g1, g2]:
p.legend.location = 'top_left'
p.title.align = 'center'
...
Alternatively, you should be able to use themes: https://docs.bokeh.org/en/latest/docs/reference/themes.html#bokeh.themes.Theme
推荐阅读
- nginx - *44 connect() 在连接上游 jhipster 时失败(111:连接被拒绝)
- android-studio - 如何在 Firebase 回收器视图 android 中放置 Admob 原生高级广告?
- stored-procedures - Informix 12.1 如何根据 case 子句中的条件选择条件
- python - 在不使用 Plotly Express 的情况下向 Plotly 子图添加垂直矩形
- html - 使用 HTML 和 JQUERY 的交互式表单
- java - Java中的窄转换和窄转换有什么区别?
- python - 将 CWD 设置为文件位置
- wordpress - twilio 是否允许我在 whatsapp 上发送特定号码的消息(从我的 wordpress 中获取)?
- c++ - 使用 Xcode 12 导入外部 C++ 库
- android - 适用于 AR 的 Google Play Services 需要最新版本错误