Python Bokeh:如何保持y轴刻度线稳定?

时间:2017-07-22 20:38:09

标签: python bokeh

通过修改gapminder.org data笔记本,我已经拍摄了一些converted to an animated gif in imageio并循环使用这些年来创建一系列图表(我Making Interactive Visualizations with Bokeh)。

4.5 MB animated gif produced by bokeh and imageio in 300 seconds and uploaded to imgur

问题在于,当中东国家在20世纪70年代浮出水面时,y轴刻度标记(和图例)会受到干扰。当我构建图表时,我会在年度循环中保留尽可能多的东西,所以我的y轴代码看起来像这样:

# Personal income (GDP per capita)
y_low = int(math.floor(income_df.min().min()))
y_high = int(math.ceil(income_df.max().max()))
y_data_range = DataRange1d(y_low-0.5*y_low, 1000000*y_high)

# ...

for year in columns_list:

        # ...

        # Build the plot
        plot = Plot(

            # Children per woman (total fertility)
            x_range=x_data_range,

            # Personal income (GDP per capita)
            y_range=y_data_range,
            y_scale=LogScale(),

            plot_width=800,
            plot_height=400,
            outline_line_color=None,
            toolbar_location=None, 
            min_border=20,
        )

        # Build the axes
        xaxis = LinearAxis(ticker=SingleIntervalTicker(interval=x_interval), 
                           axis_label="Children per woman (total fertility)", 
                           **AXIS_FORMATS)
        yaxis = LogAxis(ticker=LogTicker(), 
                        axis_label="Personal income (GDP per capita)",
                        **AXIS_FORMATS)
        plot.add_layout(xaxis, 'below')
        plot.add_layout(yaxis, 'left')

正如您所看到的,我已经将数据范围提高了10 ^ 6而没有任何影响。我需要添加一些参数来保持我的y轴刻度线(和图例)稳定吗?

1 个答案:

答案 0 :(得分:2)

不要使用DataRange1d,这是"自动测距"的实际功能。如果您知道要始终显示的完整范围,请使用Range1d

Plot(y_range=Range1d(low, high), ...) 

或更多为方便起见,这也有效:

Plot(y_range=(low, high), ...)