1

在 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)

在此处输入图像描述

然而,结果对我来说并不好,因为三个箱线图是重叠的。是否有解决方案,Plots.jl或者我应该转移到 PyPlot 或另一个 Julia 库吗?

4

1 回答 1

1

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)
于 2019-06-23T14:42:00.340 回答