我正在使用 bokeh 1.0.4,我想使用 bokeh 生成图像图match_aspect=True
。这是用于说明的示例代码:
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)
This is what I get:
数据周围有很多空白空间,对于我的应用程序来说太多了,我希望轴更紧 - 知道目前无法完美完成此操作,请参阅此其他问题 https://stackoverflow.com/questions/53617819/image-plot-in-bokeh-with-tight-axes-and-matching-aspect-ratio在“更新”部分。
所以我尝试使用该参数range_padding
,它应该与图像尺寸相关(默认单位:百分比),但它对我不起作用,例如如果我使用
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)
填充甚至更大:
小填充值,例如0.05
似乎没有效果。我也不能使用start
and end
范围的参数,因为那么
匹配的宽高比丢失。数据空间中的正方形应与屏幕上的正方形匹配。
我在使用的方式中错过了什么吗?range_padding
参数在这里?
有谁知道如何减少图像周围的空间,这样
匹配方面是否保留?
Update
我不想将绘图的高度和宽度设置为固定值,因为我还想添加一个颜色条,也许稍后添加其他东西,这将以不可预测的方式增加绘图尺寸,使得纵横比不再匹配。