Python Bokeh : How do I keep the y-axis tick marks stable?

标签 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 轴刻度线(和图例)稳定?

最佳答案

不要使用DataRange1d,这实际上是在执行“自动调整范围”。如果您知道要始终显示在前面的完整范围,请使用 Range1d:

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

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

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

关于Python Bokeh : How do I keep the y-axis tick marks stable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45258979/

相关文章:

python - 在 Django Admin 中显示组成员

python - Django 模板中两个 block 之间的可变上下文?

python - 非捕获组中的正则表达式捕获组

graph - 如何在 Bokeh 中的 networkx 图的节点上添加永久名称标签(不是交互式标签)?

python - 每个类别的 Holoviews 颜色

python - text.on_change 对 Bokeh TextInput 没有响应

python - PyPlot - 在 GUI 中向绘图添加轴标签和标题时遇到困难

python - 迭代 wxPython 中的控件以保存 session 数据

Python Bokeh 将绘图的一部分作为链接

python - 在 Bokeh 1.4.0 `xaxis.major_label_text_align` 中出现损坏