首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Gadfly中处理统计信息

在Gadfly中处理统计信息
EN

Stack Overflow用户
提问于 2020-04-06 03:54:55
回答 2查看 60关注 0票数 2

我想扩展Gadfly包以匹配我自己的特殊偏好。然而,我很难理解如何使用Gadfly的统计数据,以便在绘制之前对其输出进行处理。

例如,假设我想使用Stat.histogram产生的x,y美学。要将这些添加到图中,我知道我可以在layer()中包含Stat.histogram作为参数。但是,如果我想使用Stat.histogram计算x,y美学,使用我自己的代码编辑它们,然后绘制这些编辑后的美学,我该怎么办呢?

我正在寻找像load_aesthetics(layer(x=x, Stat.histogram))这样的函数,或者像layer(x=x, Stat.histogram).aesthetics这样的字段。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-06 14:17:19

基于@bjarthur的答案,我编写了下面的函数。

代码语言:javascript
复制
"Return the aesthetics produced by a Gadfly Statistic object."
function process_statistic(statistic::Gadfly.StatisticElement,
                           input_aesthetics::Dict{Symbol,<:Any}
                           )

    # Check that enough statistics have been provided.
    required_aesthetics = Gadfly.input_aesthetics(statistic)
    for required_aesthetic in required_aesthetics
        if required_aesthetic ∉ keys(input_aesthetics) 
            error("Aesthetic $(required_aesthetic) is required")
        end
    end

    # Create the aes object, which contains the statistics.
    aes = Gadfly.Aesthetics()
    [setfield!(aes, key, value) for (key, value) in input_aesthetics]

    # These need to be passed to the apply_statistic() function. I do
    # not understand them, and the below code might need to be edited
    # for this function to work in some cases.
    scales = Dict{Symbol, Gadfly.ScaleElement}()
    coord  = Gadfly.Coord.Cartesian()

    # This function edits the aes object, filling it with the desired aesthetics.
    Gadfly.Stat.apply_statistic(statistic, scales, coord, aes)

    # Return the produced aesthetics in a dictionary.
    outputs = Gadfly.output_aesthetics(statistic)
    return Dict(output => getfield(aes, output) for output in outputs)

end

示例用法:

代码语言:javascript
复制
process_statistic(Stat.histogram(), Dict(:x => rand(100)))
票数 1
EN

Stack Overflow用户

发布于 2020-04-06 08:35:06

您可以创建自己的统计数据。请参阅https://github.com/GiovineItalia/Gadfly.jl/issues/894

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61048626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档