JKHA
JKHA

Reputation: 1896

Plots.jl and multiple sided boxplots

In Julia, I've managed to get a boxplot with the following minimal working code:

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

However, the result is not good to me as the three boxplots are overlapping. Is there a fix with Plots.jl or should I move to PyPlot or another Julia librairy?

Upvotes: 2

Views: 2696

Answers (1)

Michael K. Borregaard
Michael K. Borregaard

Reputation: 8044

Felipe's comment is correct - you should use StatsPlots.jl, which has all the statistical recipes for Plots.jl. There's a groupedboxplot recipe which seems not to be in the readme

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

Upvotes: 4

Related Questions