首页 > 解决方案 > 具有相同大小的散景网格图的问题

问题描述

我设法gridplot在 Bokeh 中显示多个轴。但是在添加了颜色条和标签之后,地块的大小就不一样了。其中一些是狭窄的。我希望它们彼此具有相同的尺寸。我不确定这是否是由于标签和颜色条造成的。

具有不同子图宽度的图的图像。

for comp in idxComps: #adding labels
       if comp % numCols == 0:
            fig[comp].yaxis.axis_label = axLabel[1]
        if comp >= (numRows-1) * numCols:
            fig[comp].xaxis.axis_label = axLabel[0]

fig[comp].image(image=[values[..., comp].transpose()],
                      x=lower[0], y=lower[1],
                      dw=(upper[0]-lower[0]), dh=(upper[1]-lower[1]),
                      palette="Inferno256")
mapper = LinearColorMapper(palette='Inferno256',
                           low=np.amin(values[...,comp]), 
                           high=np.amax(values[...,comp]))
color_bar = ColorBar(color_mapper=mapper, 
                     width=7, 
                     location=(0,0), 
                     formatter=BasicTickFormatter(precision=1), 
                     ticker=BasicTicker(desired_num_ticks=4), 
                     label_standoff=12, 
                     border_line_color=None) #adding a color bar

fig[comp].add_layout(color_bar, 'right')


gridplot(children=fig, toolbar_location=None, ncols=numCols, sizing_mode="scale_height", merge_tools=True)

标签: pythonbokeh

解决方案


在 Bokeh 的最新版本(1.1 或更高版本)中,您可以显式传递frame_widthframe_height值来figure控制“内部”绘图区域的尺寸。


推荐阅读