【问题标题】:boxplot() got an unexpected keyword argument 'linestyle' [duplicate]boxplot()有一个意外的关键字参数'linestyle'[重复]
【发布时间】:2021-10-24 03:28:56
【问题描述】:

我正在尝试显示来自 Pandas DataFrame 的一些评级数据的箱线图。我想在箱线图中显示平均线。当我传递meanline=True 时,该行显示为点划线,但是当我传递参数linestyle='-'linestyle='--' 或以其他方式显示错误时

TypeError: boxplot() got an unexpected keyword argument 'linestyle'

我的代码是

sns.boxplot(x="rating", data=df, whis=5, color='None', showmeans=True, meanline=True, linestyle='-', linewidth=5)

如果我删除color 参数,它的默认颜色显示几乎是淡蓝色。但是当我通过color='None' 时,它会将框显示为黑色,并且平均线至少可见。我尝试了很多不同的参数组合来检查它是否有效。

现在,我想要

  • 完整的中线没有用黑色点缀,以便清晰可见

记住!主要问题是 linestyle 参数的错误与 Box 的设计无关。 希望我已经解释够了

【问题讨论】:

标签: matplotlib seaborn boxplot


【解决方案1】:

由于箱形图中有很多线,您需要告诉您要自定义哪条线。使用meanprops={'linestyle': '-'} 参数。

sns.boxplot(x="rating", data=df, whis=5, color='None', showmeans=True, meanline=True, meanprops={'linestyle'='-', 'linewidth': 5})

查看boxplot customization 上的文档了解更多详情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2017-09-26
    • 1970-01-01
    • 2016-09-12
    • 2018-04-26
    • 1970-01-01
    相关资源
    最近更新 更多