- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get boxplot data for Matplotlib boxplots?
To get boxplot data for Matplotlib boxplot we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Make data frame using pandas.
- Make a box plot from DataFrame columns.
- Get boxplot's outliers, boxes, medians and whiskers data.
- Prit all the above information.
- To display the figure, use show() method.
Example
import seaborn as sns import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(age=[23, 45, 21, 15, 12])) _, bp = pd.DataFrame.boxplot(df, return_type='both') outliers = [flier.get_ydata() for flier in bp["fliers"]] boxes = [box.get_ydata() for box in bp["boxes"]] medians = [median.get_ydata() for median in bp["medians"]] whiskers = [whiskers.get_ydata() for whiskers in bp["whiskers"]] print("Outliers: ", outliers) print("Boxes: ", boxes) print("Medians: ", medians) print("Whiskers: ", whiskers) plt.show()
Output
Outliers: [array([45])] Boxes: [array([15., 15., 23., 23., 15.])] Medians: [array([21., 21.])] Whiskers: [array([15., 12.]), array([23., 23.])]
- Related Articles
- How to change the X-axis labels for boxplots created by using boxplot function in R?
- Boxplot with variable length data in Matplotlib
- How to remove outliers from multiple boxplots created with the help of boxplot function for columns of a data frame using single line code in R?
- How to create a Boxplot with Matplotlib?
- How to set the range of Y-axis for a Seaborn boxplot using Matplotlib?
- How to create boxplots based on two factor data in R?
- How to make a grouped boxplot graph in matplotlib?
- How to get pixel coordinates for Matplotlib-generated scatterplot?
- How to create boxplot of grouped data in R?
- Plot multiple boxplots in one graph in Pandas or Matplotlib
- How to convert data values into color information for Matplotlib?
- How to color a Seaborn boxplot based on DataFrame column name in Matplotlib?
- How to deal with NaN values while plotting a boxplot using Python Matplotlib?
- How to create boxplot for matrix columns in R?
- Adding a scatter of points to a boxplot using Matplotlib

Advertisements