【问题标题】:Panda's boxplot but not showing the box熊猫的箱线图但不显示箱
【发布时间】:2014-11-05 23:10:21
【问题描述】:

有没有办法使用箱线图但只显示点?

我有这个:

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data2 = pd.DataFrame(dict(site85_574C=[10,20,30,40, 50], site41_366A=[5,15, 25, 35, 45]),  columns=["site85_574C", "site41_366A"])
data2.boxplot(widths=0.05)
plt.scatter(np.repeat(np.arange(data2.shape[1])+1, data2.shape[0]), data2.values.ravel(), marker='+', alpha=1.0)

但我只想看到垂直线上的点,而不是盒子和胡须

【问题讨论】:

    标签: python pandas ipython seaborn


    【解决方案1】:
    data2.boxplot(widths=0.05,  showbox=False, whiskerprops={'lw': 0})
    

    注意,showboxwhiskerprops 是 boxplot 的 kwds,它们依次传递给 matplotlib.boxplot

    参考

    http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.boxplot.html

    http://matplotlib.org/api/pyplot_api.html

    【讨论】:

    • 我得到一个“boxplot() got an unexpected keyword argument 'whiskerprops'”。我看到你在熊猫文档中引用的 kwds 项目。它似乎并没有让我通过这些。有什么想法吗?
    • 很奇怪。也许你的 matplotlib 已经过时了?
    • 是的..就是这样..更新,一切正常!谢谢!
    猜你喜欢
    • 2017-12-09
    • 2017-09-09
    • 1970-01-01
    • 2021-10-14
    • 2017-03-20
    • 2017-02-28
    • 2018-10-15
    • 2015-05-04
    • 2013-05-21
    相关资源
    最近更新 更多