Home > OS >  How to plot a box plot with two summary statistics using Matplotlib?
How to plot a box plot with two summary statistics using Matplotlib?

Time:02-11

I have summary statistics for my data:

Summary 1: min = 0, 1st quarter = 5, median = 200, mean = 455, 3rd quarter = 674, max = 980

Summary 2: min = 1, 1st quarter = 7.5, median = 254, mean = 586, 3rd quarter = 851, max = 1021

I want to plot box plot using matplotlib from these statistics by plotting Summary 1 and 2 side by side.

I can plot the graph (box plot) for each of the summary separately (two graph) but couldn't do it in single plot.

I am using below code for separate box plot:

import matplotlib.pyplot as plt

stats = [{
    "label": 'Summary 1',  # not required
    "mean":  455,  # not required
    "med": 200,
    "q1": 5,
    "q3": 674,
    "whislo": 0,  # required (min)
    "whishi": 980,  # required (max)
    "fliers": []  # required if showfliers=True
    }]


fs = 10  # fontsize

fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(6, 6), sharey=True)
axes.bxp(stats)
axes.set_title('Boxplot for Summary 1', fontsize=fs)
plt.show()  

Can anyone tell me how can I do it?

Thanks in Advance!

CodePudding user response:

Looking at the value of stats in boxplots

  • Related