Plots.jl和多面框线图

时间:2019-06-20 07:23:35

标签: 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图书馆?

1 个答案:

答案 0 :(得分: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)