Ask Your Question
2

Can a matplotlib boxplot be created using percentile values in place of the original inputs?

asked 2023-05-12 12:36:12 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-12 12:49:02 +0000

ladyg gravatar image

Yes, a matplotlib boxplot can be created using percentile values in place of the original inputs. This can be done by specifying the percentile values as the data for the boxplot function, instead of the original inputs.

For example, if you have a list of data and you want to create a boxplot using the 10th, 25th, 50th, 75th, and 90th percentiles, you can calculate these values using numpy and then pass them as the data for the boxplot function:

import numpy as np
import matplotlib.pyplot as plt

# create some sample data
data = np.random.randn(100)

# calculate the percentiles
p10, p25, p50, p75, p90 = np.percentile(data, [10, 25, 50, 75, 90])

# create the boxplot using the percentiles
plt.boxplot([p10, p25, p50, p75, p90])
plt.show()

This will create a boxplot using the percentiles as the data, instead of the original data points.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-12 12:36:12 +0000

Seen: 12 times

Last updated: May 12 '23