0

I have created a box plot using Matplotlib. I am trying to label the five number summary of a box plot(Lower Quartile,median,Upper Quartile,minimum,maximum and outliers) using matplotlib library,but I have no idea on how to do it.Can someone help me out? Thanks in advance.

vehicle_class_ticks = np.arange(len(vehicle_class_unique))
plt.title('COE Quota grouped by categories')
plt.xlabel('Different Types of Vehicle Class')
plt.ylabel('Total Number of COE Quota')
plt.boxplot(Cat_quota_array.transpose(),labels=vehicle_class_unique,patch_artist=True)
plt.show()
print('-----------------------------------------------------------------------------------------------------------------------')
catA_min_value = min(catA_quota)
catA_max_value = max(catA_quota)
catA_median = np.median(catA_quota)
catA_upper_quartile = np.percentile(catA_quota,75)
catA_lower_quartile = np.percentile(catA_quota,25)
catA_interquartile = catA_upper_quartile - catA_lower_quartile
print('Category A shows a positively skewed box plot')
print(f'The Minimum COE Quota Value of Category A is {catA_min_value}')
print(f'The Maximum COE Quota Value of Category A is {catA_max_value}')
print(f'The Median Quota Value for Category A is {catA_median}')
print(f'The Lower Quartile Range Quota Value for Category A is {catA_lower_quartile}')
print(f'The Upper Quartile Range Quota Value for Category A is {catA_upper_quartile}')
print(f'The Interquartile range for Category A is {catA_interquartile}');print()

catB_min_value = min(catB_quota)
catB_max_value = max(catB_quota)
CatB_median = np.median(catB_quota)
catB_upper_quartile = np.percentile(catB_quota,75)
catB_lower_quartile = np.percentile(catB_quota,25)
catB_interquartile = catB_upper_quartile - catB_lower_quartile
print('Category B shows a positively skewed box plot')
print(f'The Minimum COE Quota Value of Category B is {catB_min_value}')
print(f'The Maximum COE Quota Value of Category B is {catB_max_value}')
print(f'The Median Quota Value for Category B is {CatB_median}')
print(f'The Lower Quartile Range Quota Value for Category B is {catB_lower_quartile}')
print(f'The Upper Quartile Range Quota value for Category B is {catB_upper_quartile}')
print(f'The Interquartile range for Category B is {catB_interquartile}');print()

catC_min_value = min(catC_quota)
catC_max_value = max(catC_quota)
CatC_median = np.median(catC_quota)
catC_upper_quartile = np.percentile(catC_quota,75)
catC_lower_quartile = np.percentile(catC_quota,25)
catC_interquartile = catC_upper_quartile - catC_lower_quartile
print('Category C shows a almost symmetrical box plot')
print(f'The Minimum COE Quota Value of Category C is {catC_min_value}')
print(f'The Maximum COE Quota Value of Category C is {catC_max_value}')
print(f'The Median Quota Value for Category C is {CatC_median}')
print(f'The Lower Quartile Range Quota Value for Category C is {catC_lower_quartile}')
print(f'The Upper Quartile Range Quota Value for Category C is {catC_upper_quartile}')
print(f'The Interquartile range for Category C is {catC_interquartile}')
print(f'Category C has shown to have outliers which falls around the 2000 range.');print()

catD_min_value = min(catD_quota)
catD_max_value = max(catD_quota)
CatD_median = np.median(catD_quota)
catD_upper_quartile = np.percentile(catD_quota,75)
catD_lower_quartile = np.percentile(catD_quota,25)
catD_interquartile = catD_upper_quartile - catD_lower_quartile
print('Category D shows a postively skewed box plot')
print(f'The Minimum COE Quota Value of Category D is {catD_min_value}')
print(f'The Maximum COE Quota Value of Category D is {catD_max_value}')
print(f'The Median Quota Value for Category D is {CatD_median}')
print(f'The Lower Quartile Range Quota Value for Category D is {catD_lower_quartile}')
print(f'The Upper Quartile Range Quota Value for Category D is {catD_upper_quartile}')
print(f'The Interquartile range for Category D is {catD_interquartile}')
print('Category D has shown to have multiple outliers from the estimated range of 1500 to 2100')

enter image description here

RhinoCoder
  • 11
  • 4
  • See the excellent response [How to annotate boxplot median, quartiles, and whiskers](https://stackoverflow.com/questions/40813813/how-to-annotate-boxplot-median-quartiles-and-whiskers). – r-beginners Dec 12 '22 at 08:25

0 Answers0