Obtaining values used in boxplot, using python and matplotlib

后端 未结 2 740
Happy的楠姐
Happy的楠姐 2020-12-14 02:56

I can draw a boxplot from data:

import numpy as np
import matplotlib.pyplot as plt

data = np.random.rand(100)
plt.boxplot(data)

Then, the

2条回答
  •  鱼传尺愫
    2020-12-14 03:32

    Why do you want to do so? what you are doing is already pretty direct.

    Yeah, if you want to fetch them for the plot, when the plot is already made, simply use the get_ydata() method.

    B = plt.boxplot(data)
    [item.get_ydata() for item in B['whiskers']]
    

    It returns an array of the shape (2,) for each whiskers, the second element is the value we want:

    [item.get_ydata()[1] for item in B['whiskers']]
    

提交回复
热议问题