簡體   English   中英

Python Bokeh:如何保持y軸刻度線穩定?

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

在這里,我已經獲取了一些gapminder.org數據,並通過多年來的循環來創建一系列圖表(通過使用Bokeh筆記本進行“交互式可視化”來創建圖表( 在imageio中將轉換為動畫gif )。

4.5 MB的gif動畫,由bokeh和imageio在300秒內生成並上傳到imgur

問題在於,當中東國家在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軸刻度線(和圖例)穩定嗎?

不要使用DataRange1d ,這實際上是在做“自動調整范圍”。 如果您知道要始終顯示在前面的完整范圍,請使用Range1d

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

或更多方便起見,這也將起作用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM