使用 Matplotlib 后端控制 Holoviews + Datashader 的大小

Issue Controlling Size of Holoviews + Datashader with Matplotlib Backend

我目前正在尝试将 holoviews+datashader 与 matplotlib 后端一起使用。我使用的数据具有非常不同的 x 和 y 范围,结果是数据着色器图被无益地拉伸了。我尝试使用的 opts 和 output 关键字可以解决 holoviews only plots 的问题,但一旦应用了 datashade 就不能。

例如:

import holoviews as hv
hv.extension('matplotlib')
import numpy as np
from holoviews.operation.datashader import datashade

np.random.seed(1)
positions = np.random.multivariate_normal((0,0),[[0.1,0.1], [0.1,50.0]], (1000000,))
positions2 = np.random.multivariate_normal((0,0),[[0.1,0.1], [0.1,50]], (1000,))
points = hv.Points(positions,label="Points")
points2 = hv.Points(positions2,label="Points2")
plot = datashade(points) + points2
plot

生成: datashader and points output

我可以使用 fig_size opts 关键字控制仅点图的大小

e.g. points2(plot=dict(fig_size=200))

但这同样不适用于数据着色器图。对于使用 matplotlib 更改此类数据着色器图形大小的任何建议,我们将不胜感激。理想情况下,我想使用函数而不是单元格魔术关键字,以便可以将代码移植到脚本中。

谢谢!

更改 HoloViews 中 matplotlib 图的大小始终由外部容器控制,因此当您拥有布局时,您可以更改该对象的大小,例如在你的例子中是:

plot = datashade(points) + points2
plot.opts(plot=dict(fig_size=200))

另一个可能令人困惑的部分是 RGB 元素(这是数据阴影操作 returns)默认使用 aspect='equal'。您可以通过将纵横比设置为 'square' 或明确的纵横比来更改它:

datashade(points).opts(plot=dict(fig_size=200, aspect='square'))

把它们放在一起你可能想做这样的事情:

plot = datashade(points).opts(plot=dict(aspect='square')) + points2
plot.opts(plot=dict(fig_size=200))