Rizky A Fauzan
Rizky A Fauzan

Reputation: 51

How to make boxplot using matplotlib when i already have all the information?

Can you guys help me for my statistics problem? I'm trying to make Box Plot exactly like this :

1

I have all the information to make like :

# Median  
medianResult = specificData.median()

# Percentile 25
Q1 = specificData.quantile(0.25)

# Percentile 75
Q3 = specificData.quantile(0.75)


# Reasonable Upper Boundary (RUB)
RUB = Q3 + (1.5 * IQRResult)

# Reasonable Lower Boundary (RLB)
RLB = Q1 - (1.5 * IQRResult)

is there any other information do i need to make BoxPlot? and how to make one like exactly from the picture above? Sorry if my english bad.. Thank you for your help guys

Upvotes: 0

Views: 185

Answers (1)

JohanC
JohanC

Reputation: 80459

You can call matplotlib's ax.bxp(...) directly. It accepts a list of dictionaries as its first parameter. Here is an example to get you started:


import matplotlib.pyplot as plt

medianResult = 49
# Percentile 25
Q1 = 44
# Percentile 75
Q3 = 57
IQRResult = Q3 - Q1
# Reasonable Upper Boundary (RUB)
RUB = Q3 + (1.5 * IQRResult)
# Reasonable Lower Boundary (RLB)
RLB = Q1 - (1.5 * IQRResult)

stat_dict1 = {'med': medianResult,
              'q1': Q1,
              'q3': Q3,
              'whislo': RLB,
              'whishi': RUB,
              'fliers': [15, 18],
              'label': 'Example'}
fig, ax = plt.subplots()
ax.bxp(bxpstats=[stat_dict1])
plt.show()

example boxplot

Upvotes: 1

Related Questions