julia - Plots.jl 和多边箱线图

标签 julia plots.jl

在 Julia 中,我成功地使用以下最少的工作代码获得了箱线图:

using Plots
using DataFrames

function boxplot_smaa_similarity(arr_nb_alternative::Vector{Int}, 
                                 arr_nb_montecarlo::Vector{Int}, 
                                 nb_criteria::Int, nb_simulations::Int)
    # Create a fill dataframe
    df = DataFrame(NbAlternative = Int[], NbMonteCarlo = Int[], Similarity = Float64[])
    for na in arr_nb_alternative
        @show na
        for mt in arr_nb_montecarlo
            println()
            println("...$mt")
            append!(df, (NbAlternative=ones(Int, nb_simulations)*na,
                        NbMonteCarlo=ones(Int, nb_simulations)*mt,
                        Similarity=rand(Float64, nb_simulations)))
        end
    end

    # Boxplot dataframe data
    p = Plots.boxplot(df[:NbMonteCarlo], 
                      df[:Similarity], 
                      group = df[:NbAlternative], 
                      ylims = (0.0, 1.1), 
                      xlabel ="Nb Simulations Monte Carlo", 
                      ylabel = "Similarity", 
                      dpi = 500)

   # Save figure to path, do not hesitate to change path if necessary
    Plots.savefig("../output/plot_compare_SMAA-TRI-AD_crit$(nb_criteria)"*
                  "_nb_alternative_$(arr_nb_alternative[1])-$(arr_nb_alternative[end])"*
                  "_nb_MC$(arr_nb_montecarlo[1])-$(arr_nb_montecarlo[end]).png")
    return p
end

boxplot_smaa_similarity([50,100,150], [2,4,6,8,10], 5, 10)

enter image description here

但是,结果对我来说并不好,因为三个箱线图重叠。 Plots.jl 是否有修复,或者我应该转移到 PyPlot 或另一个 Julia 库?

最佳答案

Felipe 的评论是正确的 - 您应该使用 StatsPlots.jl,其中包含 Plots.jl 的所有统计方法。有一个 groupedboxplot 配方似乎不在自述文件中

a = rand(1:5, 100)
b = rand(1:5, 100)
c = randn(100)
using StatsPlots
groupedboxplot(a, c, group = b, bar_width = 0.8)

关于julia - Plots.jl 和多边箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56680978/

相关文章:

julia - 抑制图例中的某些标签或放置采样标记

latex - 剧情+ Julia + latex

julia - parse() 什么时候应该抛出错误?

functional-programming - 多参数和嵌套函数的函数组合

string - 如何在Julia中使字符串的大写字母变为特定字母?

dataframe - 在 Julia 的绘图函数中使用运算符

julia - 使用 Plots.jl 将一组图绘制为子图

colors - Julia Plots.heatmap 颜色的日志比例不起作用

io - 将所有输出重定向到 Julia 中的文件

Julia 中的 Elasticsearch 查询