Reputation: 1384
I would expect the following code to set only the upper bound of the plot y range, however the lower bound is also inexplicably set to 0:
import bokeh.plotting as bkp
import numpy as np
bkp.output_file("/tmp/test_plot.html")
fig = bkp.figure(y_range=[None, 100]) # plot y range: 0-100
# fig = bkp.figure() # plot y range: 50-100
fig.line(np.linspace(0, 1, 200), np.random.random(200)*50+50) # number range: 50-100
bkp.save(fig)
Why does this happen? What's the easiest way to set only 1 range bound?
Upvotes: 6
Views: 2987
Reputation: 34568
You are replacing the auto-ranging default DataRange1d
with a "dumb" (non-auto ranging) Range1d
. Set the end
value of the default range that the plot creates, without replacing the entire range. Or alternatively, replace with a new DataRange1d
:
from bokeh.models import DataRange1d
p = figure(y_range=DataRange1d(end=100))
or
p.y_range.end = 100
Upvotes: 6
Reputation: 426
The Range1d(start=None, end=100)
(as you are also referring to in your comments) is only defining your initial view. It doesn't make sense for a Range to not have both a starting point and an ending point, so if you give it start=None
, it will just use its default value which is 0
.
I think what you are trying to do is something like this:
Range1D(start=value1, end=value2, bounds=(None, 100))
This will give you an upper bound of 100 and no lower bound.
See docs for more specifications and examples.
Edit: okay, I initially ready your question as though you were trying to set the bounds. You want to use the DataRange1D
class instead, then. If you just make sure to not override the start
, it will default to "auto".
In other words, this should do what you want:
DataRange1D(end=100)
Upvotes: 0