Search code examples
pythonseabornboxplot

How do you create a boxplot in seaborn with pre-calculated values for mean, median, percentile, etc?


I would like to create a boxplot in seaborn or matplotlib where I can manually enter the values for a boxplot instead of having those values calculated from a data set.

I am trying to compare actual data to target values so I'd like to show those targets as a box plot and then overlay a swarmplot of actual data points. For example. I have a data frame with a different compensation classes with these desired targets:

    Grade                                GN23
    MINIMUM (Start of 1st Quartile)     94603
    1st Q (End of 1st Quartile)        113524
    MIDPOINT (End of 2nd Quartile)     132444
    3rd Q (End of 3rd Quartile)        151365
    MAXIMUM (End of 4th Quartile)      170285

I'd like to create boxplot with those parameters. Is that possible?


Solution

  • You can probably just input those values as the data like this:

    import matplotlib.pyplot as plt
    import seaborn as sns
    
    sns.boxplot(data=[94603, 113524, 132444, 151365, 170285])
    
    plt.show()
    

    enter image description here

    Since there are only 5 values, the first one would be the minimum, the second one would be Q1, etc.