pandas - matplotlib:每个类别的箱线图

标签 pandas matplotlib boxplot

我的 Pandas 数据框有两列:categoryduration .和
我使用以下代码制作所有数据点的箱线图。

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')

enter image description here

关于pandas - matplotlib:每个类别的箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48712274/

相关文章:

r - R中倾斜箱线图的x标签

python - 对 Python Pandas Dataframe 中的行重新排序

python - 查找定义范围内的值的子范围

python - matplotlib 中的颜色

python - Matplotlib 直方图不显示分布细节

python - Matplotlib,类型错误 : ord() expected a character, 但找到长度为 0 的字符串

python - 重命名 pandas Dataframe 列及其下的数据

python - 如何拆分数据框单元格中的数据并在拆分时执行 Pandas groupby?

python - Seaborn load_dataset

r - 使用 ggplot2 从矩阵创建箱线图