【问题标题】:Python Bokeh: How do I keep the y-axis tick marks stable?Python Bokeh:如何保持 y 轴刻度线稳定?
【发布时间】:2017-07-24 03:40:15
【问题描述】:

在这里,我采取了一些gapminder.org data 并通过修改Making Interactive Visualizations with Bokeh 笔记本来创建一系列图表(我converted to an animated gif in imageio)。

问题在于,当中东国家在 1970 年代浮出水面时,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 轴刻度线(和图例)稳定吗?

【问题讨论】:

    标签: python bokeh


    【解决方案1】:

    不要使用DataRange1d,这实际上是在做“自动量程”。如果您知道要始终显示在前面的全部范围,请使用Range1d

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

    或更多为方便起见,这也可以:

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

    【讨论】:

    • 解决了!谢谢。
    猜你喜欢
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多