I'm using bokeh 1.0.4 and I would like to generate an image plot in bokeh using match_aspect=True
. Here is a example code for illustration:
from bokeh.models.ranges import DataRange1d
from bokeh.plotting import figure, show
import numpy as np
arr = np.array([[1,2,3],[4,5,6]])
plot = figure(match_aspect=True)
plot.image([arr], x=0, y=0, dw=3, dh=2)
show(plot)
There is a lot empty space around the data, too much for my application, and I would like to have the axes more tight - knowing that this currently cannot perfectly be done, see this other question in section "Update".
So I've tried to use the parameter range_padding
, which should be relative to the image dimensions (default unit: percent), but it doesn't work for me, e.g. if I use
from bokeh.models.ranges import DataRange1d
from bokeh.plotting import figure, show
import numpy as np
arr = np.array([[1,2,3],[4,5,6]])
x_range = DataRange1d(range_padding=5, range_padding_units='percent')
y_range = DataRange1d(range_padding=5, range_padding_units='percent')
plot = figure(x_range=x_range, y_range=y_range, match_aspect=True)
plot.image([arr], x=0, y=0, dw=3, dh=2)
show(plot)
the padding is even larger:
Small padding values like 0.05
seem to have no effect. Also I cannot use start
and end
arguments for the ranges because then the
matching aspect ratio is lost. A square in data space should match a square on the screen.
Did I miss something in the way I use the range_padding
parameters here?
Does anybody have an idea how to reduce the space around the image such that
the matching aspect is kept?
Update
I would like not to set plot's height and width to fixed values, because I also want to add a colorbar and maybe other things later and this will increase the plot dimensions in an unpredictable way such that the aspect ratios don't match any more.