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

时间:2017-10-03 14:36:12

标签: python graph bokeh

我有一个图表,它在4个不同的y轴刻度上显示多行。当我向侧面添加第二个y轴时,仅显示第一个轴的标签。如何显示第二轴标签?

示例:

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)

Example Graph

从上面的示例中,仅显示压力和液体流量轴标签。如何显示温度和气体流量轴标签?

1 个答案:

答案 0 :(得分:1)

这可能是你的散景版。我目前正在使用散景版0.12.7并且您的代码没有修改,结果如下: enter image description here

对于散景版0.12.9 ,解决方法是指定一些较大的min_border_leftmin_border_right,例如

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

额外轴的标签之间的间隔比正常大:

enter image description here