1

Here I've taken some gapminder.org data and looped through the years to create a series of charts (which I converted to an animated gif in imageio) by modifying the Making Interactive Visualizations with Bokeh notebook.

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

The problem is that when the Middle Eastern countries float to the top in the 1970s, the y-axis tick marks (and the legend) gets perturbed. I'm keeping as many things as possible out of the year loop when I build the plots, so my y-axis code looks like this:

# 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')

As you can see, I've bumped up the data range by a factor of 10^6 with no effect. Is there some parameter I need to add to keep my y-axis tick marks (and legend) stable?

Dave Babbitt
  • 1,038
  • 11
  • 20

1 Answers1

2

Don't use a DataRange1d, that's what is actually doing the "auto-ranging". If you know the full range that you want to always show up front use a Range1d:

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

or more for convenience this will also work:

Plot(y_range=(low, high), ...) 
bigreddot
  • 33,642
  • 5
  • 69
  • 122