【问题标题】:python: default settings for plt.pyplot.boxplot?python:plt.pyplot.boxplot 的默认设置?
【发布时间】:2014-12-03 01:16:15
【问题描述】:
>>>import matplotlib.pyplot as plt
>>>data = [1,2,3,4,5]                # toy data
>>>boxplot = plt.boxplot(data)

返回一个dict类型的箱线图对象,其键是:

>>>boxplot.keys()
['medians', 'fliers', 'whiskers', 'boxes', 'caps']

我想知道如何查询 matplotlib 用于生成这些箱线图属性的默认设置。 Google 帮不上什么忙。

例如,如何查询生成箱线图的“boxes”属性的设置?它们是第 25 和第 75 个百分位数吗?

【问题讨论】:

  • 你看过 print plt.boxplot.__doc__ 吗?至少对于胡须来说,它似乎是第 25 和第 75 个百分位数: whis : [ 默认 1.5 ] 将胡须的长度定义为内四分位数范围的函数。它们扩展到 (whis*(75%-25%)) 数据范围内的最极端数据点。
  • 嗯,非常有用,谢谢
  • 这个问题对我来说有点不清楚。你的意思是文档不让你满意吗?如果是这样,您能否列出具体问题而不是不太清楚的“查询默认设置”?我现在的回答是“如果谷歌、文档或 SO 到目前为止没有帮助 - 查看代码”,我认为这不会让你满意,尽管它完全回答了所提出的问题。

标签: python matplotlib boxplot


【解决方案1】:

您只需拨打print(plt.boxplot.__doc__)即可获取您需要的信息:

这里有一段相关的摘录(整件事真的很长):

whis : float, sequence (default = 1.5) or string
        As a float, determines the reach of the whiskers past the first
        and third quartiles (e.g., Q3 + whis*IQR, IQR = interquartile
        range, Q3-Q1). Beyond the whiskers, data are considered outliers
        and are plotted as individual points. Set this to an unreasonably
        high value to force the whiskers to show the min and max values.
        Alternatively, set this to an ascending sequence of percentile
        (e.g., [5, 95]) to set the whiskers at specific percentiles of
        the data. Finally, *whis* can be the string 'range' to force the
        whiskers to the min and max of the data. In the edge case that
        the 25th and 75th percentiles are equivalent, *whis* will be
        automatically set to 'range'.

所以是的,它是第 25 个和第 75 个百分位数,因为默认值是相对于中位数的 1.5。

【讨论】:

    猜你喜欢
    • 2010-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 2016-04-25
    相关资源
    最近更新 更多