【问题标题】:Issue Controlling Size of Holoviews + Datashader with Matplotlib Backend使用 Matplotlib 后端控制 Holoviews + Datashader 的大小
【发布时间】:2018-02-02 21:02:40
【问题描述】:

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

例如:

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 更改此类数据着色器图形大小的建议将不胜感激。理想情况下,我想使用函数而不是单元格魔术关键字,以便将代码移植到脚本中。

谢谢!

【问题讨论】:

    标签: python holoviews datashader


    【解决方案1】:

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

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

    另一个可能令人困惑的部分是 RGB 元素(这是 datashade 操作返回的内容)默认使用 aspect='equal'。您可以通过将 aspect 设置为“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))
    

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 2014-11-20
      • 2019-05-30
      • 2017-11-01
      • 1970-01-01
      相关资源
      最近更新 更多