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

2024-09-27 00:16:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在尝试在matplotlib后端使用holoviews+datashader。我使用的数据具有非常不同的x和y范围,结果是datashader图被拉伸得毫无帮助。我尝试使用的opts和output关键字可以解决holoviews只绘制图的问题,但一旦应用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关键字控制点的大小

^{pr2}$

但同样的方法不适用于datashader图。任何关于用matplotlib改变这种数据阴影图形大小的建议都将不胜感激。理想情况下,我希望使用函数而不是cellmmagic关键字,这样代码就可以移植到脚本中。在

谢谢!在


Tags: 数据importoutputmatplotlibasnprandom关键字
1条回答
网友
1楼 · 发布于 2024-09-27 00:16:00

在HoloViews中更改matplotlib绘图的大小总是由外部容器控制的,因此当您有一个布局时,您可以更改该对象的大小,例如,在您的示例中:

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

另一个可能令人困惑的地方是,RGB元素(datashade操作返回的内容)默认使用aspect='equal'。您可以通过将纵横比设置为“正方形”或显式纵横比来更改该值:

^{pr2}$

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

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

相关问题 更多 >

    热门问题