简体   繁体   English

散景:在同一侧显示具有多个 Y 轴的附加 Y 轴标签

[英]Bokeh: Display Additional Y-Axis Label with Multiple Y-Axis on the Same Side

I have a graph which is to display multiple lines, on 4 different y-axis scales.我有一个图表,用于在 4 个不同的 y 轴刻度上显示多条线。 When I add a second y-axis to a side, only the label of the first axis is displayed.当我向一侧添加第二个 y 轴时,只显示第一个轴的标签。 How can I have the 2nd axis label be shown?如何显示第二个轴标签?

Example:例子:

from bokeh.models import Range1d, LinearAxis
from bokeh.plotting import figure
from bokeh.io import show, output_notebook

output_notebook()

fig = figure()

# Define x-axis
fig.xaxis.axis_label = 'Date'

# Define 1st LHS y-axis
fig.yaxis.axis_label = 'Pressure [barg]'
fig.y_range = Range1d(start=0, end=200)

# Create 2nd LHS y-axis
fig.extra_y_ranges['temp'] = Range1d(start=0, end=50)
fig.add_layout(LinearAxis(y_range_name='temp', axis_label='Temperature [°C]'), 'left')

# Create 1st RHS y-axis
fig.extra_y_ranges['lflow'] = Range1d(start=0, end=50000)
fig.add_layout(LinearAxis(y_range_name='lflow', axis_label='Liquid Flowrate [bbl/day]'), 'right')

# Create 2nd RHS y-axis
fig.extra_y_ranges['gflow'] = Range1d(start=0, end=50)
fig.add_layout(LinearAxis(y_range_name='gflow', axis_label='Gas Flowrate [MMscf/day]'), 'right')

fig.line(
    x = [0,1,2,3,4,5],
    y = [80,88,87,70,77,82],
    legend = 'Pressure',
    color = 'purple'
)

fig.line(
    x = [0,1,2,3,4,5],
    y = [5,6,5,5,5,4],
    legend = 'Temperature',
    y_range_name = 'temp',
    color = 'red'
)

fig.line(
    x = [0,1,2,3,4,5],
    y = [10000,10100,10000,10150,9990,10000],
    legend = 'Liquid Flowrate',
    y_range_name = 'lflow',
    color = 'orange'
)


fig.line(
    x = [0,1,2,3,4,5],
    y = [35,37,40,41,40,36],
    legend = 'Gas Flowrate',
    y_range_name = 'gflow',
    color = 'green'
)

fig.toolbar_location = 'above'

show(fig)

示例图

From the example above, only the Pressure and Liquid Flowrate axis labels are displayed.在上面的示例中,仅显示压力和液体流速轴标签。 How can I make the Temperature and Gas Flowrate axis labels display?如何显示温度和气体流速轴标签?

It might be your bokeh version.这可能是您的散景版本。 I am currently using bokeh version 0.12.7 and your code without modifications and the result is as follows:我目前使用的是散景版本 0.12.7,你的代码没有修改,结果如下: 在此处输入图片说明

For bokeh version 0.12.9 a workaround is to specify some large min_border_left and min_border_right , eg对于散景版本 0.12.9 ,解决方法是指定一些大的min_border_leftmin_border_right ,例如

fig = figure(plot_width=700,min_border_left=150,min_border_right=170)

The separation between the labels of the extra axes is larger than normal:额外轴的标签之间的间隔比正常大:

在此处输入图片说明

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

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