Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python bokeh modify axis scale

Tags:

python

axis

bokeh

How can I modify the y-axis scale at figures and at charts? I want something like this: my_figure.y_range.end = my_figure.y_range.end * 1.3

So I want a bit higher y-axis. Thank you!

like image 363
ragesz Avatar asked Jan 21 '16 16:01

ragesz


1 Answers

Figure uses DataRange1d objects by default, which causes the range to automatically computed. But this happens on the browser, because it takes into account information like glyph extent that are only available at render time. The reason that my_figure.y_range.end * 1.3 does not work is because the "automatic" value of end is not known yet. It is only set automatically inside the browser. You can override the "automatic" behaviour of a DataRange by supplying start and end, but you have to give it an explicit, numeric value that you want, i.e.:

my_figure.y_range.end = 10

Alternatively, DataRange1d models have range_padding property that you can set, which controls the amount of "extra padding" added to the automatically computed bounds. It is described here:

http://docs.bokeh.org/en/latest/docs/reference/models/ranges.html#bokeh.models.ranges.DataRange1d.range_padding

This might accomplish what you want in a different way, but note that it affects both start and end.

Finally, if you'd just like to completely control the range, without having auto ranging at all, you can do this when you create the figure:

p = figure(..., x_range=(10, 20))

This will create a fixed Range1d for the x-axis with start=10 and end=20.

like image 140
bigreddot Avatar answered Oct 21 '22 08:10

bigreddot