在 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 库吗?