Skip to content Skip to sidebar Skip to footer

Smaller Range Padding For Image Plot With Bokeh

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 DataRang

Solution 1:

Is this work-around acceptable for you (Bokeh v1.0.4)?

from bokeh.models.ranges import DataRange1d
from bokeh.plotting import figure, showfrom bokeh.layouts import Rowfrom bokeh.palettes import Greys
from bokeh.models import LinearColorMapper, ColorBar
import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])

sx =3
sy =2

x_range = DataRange1d(start=0, end= sx, bounds = (0, sx), range_padding =5, range_padding_units ='percent')
y_range = DataRange1d(start=0, end= sy, bounds = (0, sy), range_padding =5, range_padding_units ='percent')

pw =400
ph = pw * sy / sx
plot = figure(plot_width = pw,
              plot_height = ph,
              x_range = x_range,
              y_range = y_range,
              match_aspect =True)
plot.image([arr], x =0, y =0, dw = sx, dh = sy)

color_mapper = LinearColorMapper(palette = Greys[6], low = arr.min(), high = arr.max())
colorbar_plot = figure(plot_height = ph, plot_width =69, x_axis_location =None, y_axis_location =None, title =None, tools ='', toolbar_location =None)
colorbar = ColorBar(color_mapper = color_mapper, location = (0, 0))
colorbar_plot.add_layout(colorbar, 'left')

show(Row(plot, colorbar_plot))

Result:

enter image description here

Post a Comment for "Smaller Range Padding For Image Plot With Bokeh"