Default behaviour y_range when plotting line

I would like to know bokeh’s default behaviour for setting the y_range when plotting a line, when ‘y_range’ is not given as an argument when creating the figure.
In the documentation (Plotting with basic glyphs — Bokeh 2.4.2 Documentation) I read “Bokeh attempts to automatically set the data bounds of plots to fit snugly around the data”, but how does it do that?

I want to implement/copy/mimic this behaviour when I add an y-axis with “extra_y_ranges” to a figure.

So far I searched the documentation, google and stackoverflow with no success. Also I tried the go through the source of bokeh to find out myself, also without any luck.

Any help is very much appriciated.

Auto-ranging is performed by using a DataRange1d. If you search the examples in the repo you can see several instances of using/configuring them.

However, I am not 100% that using an auto-range for an “extra” range is supported. It may work (or “work”), but you will just have to experiment and see. When there are extra ranges, Bokeh tries to keep the initial relative scales of all the ranges “locked” together (e.g so that they stay the same when zooming and panning). But I am not sure this constraint is consistent with dynamic auto-ranging, so the result may just be “undefined behavior”. YMMV

Also, for reference, the source code for auto-ranging is here:

bokeh/data_range1d.ts at branch-3.0 · bokeh/bokeh · GitHub

In case it was not evident, auto-ranging does not happen on the “Python side”. Everything is computed in the “browser side”, in JavaScript.

Also FYI this is literally one of the most complicated corners of Bokeh. Auto-ranging has to consider: start/end overrides from users, absolute or relative range padding options, data-following modes, hard bounds (if/when they are set), min/max range interval configurations, responding to data updates, responding to the addition and subtraction of glyphs themselves, handling flipped ranges, taking into account glyph visibility, linear vs log scales, aspect ratio preservation… all while in an interactive plot that may have pan/zoom or other range influencing tools. Just a very surprising number of things all intersect in this one place. [1]

  1. Which is also why things may not work with “extra” ranges. As the number of features grows, every marginal feature addition add an entire new dimension of complexity as it intersects with every previous feature. ↩︎

Thanks so much. Your answer made things clear for me :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.