我的 Pandas 数据框有两列:category
和 duration
.和
我使用以下代码制作所有数据点的箱线图。
import matplotlib.pyplot as plt
plt.boxplot(df.duration)
plt.show()
但是,如果我想要每人一盒
category
,如何修改上面的代码?谢谢!
最佳答案
除了Wen's answer ,这是现货,您可能想查看 the seaborn library .它是为了做这种情节而制作的。
Seaborn is a Python visualization library based on matplotlib. It provides a high-level interface for drawing attractive statistical graphics.
检查 documentation for boxplots
Draw a box plot to show distributions with respect to categories.
sns.boxplot(data=df, x='category', y='duration')
关于pandas - matplotlib:每个类别的箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48712274/