【发布时间】:2014-10-17 00:41:29
【问题描述】:
我一直在绞尽脑汁想弄清楚如何以我想要的方式绘制 pandas DataFrame,但无济于事。
DataFrame 有一个 MultiIndex,它看起来像这样:
+-----------+--------------+------------+--------------+-----------------+---------+---------+---------+---------+---------+
| | | | | | run_001 | run_002 | run_003 | run_004 | run_005 |
+-----------+--------------+------------+--------------+-----------------+---------+---------+---------+---------+---------+
| file_type | server_count | file_count | thread_count | cacheclear_type | | | | | |
+-----------+--------------+------------+--------------+-----------------+---------+---------+---------+---------+---------+
| gor | 01servers | 05files | 20threads | ccALWAYS | 15.918 | 16.275 | 15.807 | 17.781 | 16.233 |
| gor | 01servers | 10files | 20threads | ccALWAYS | 17.322 | 17.636 | 16.096 | 16.484 | 16.715 |
| gor | 01servers | 15files | 20threads | ccALWAYS | 19.265 | 17.128 | 17.630 | 18.739 | 16.833 |
| gor | 01servers | 20files | 20threads | ccALWAYS | 23.744 | 20.539 | 21.416 | 22.921 | 22.794 |
+-----------+--------------+------------+--------------+-----------------+---------+---------+---------+---------+---------+
我想要做的是绘制一个折线图,其中 x 值是“file_count”值,每个 y 值是 DataFrame 中相应行的所有 run_xxx 值的平均值。
如果可能的话,我想添加误差线,甚至是数据点本身,这样我就可以看到平均值背后的数据分布。
这是一个(蹩脚的)大体上我在说什么的模型:
我已经能够使用内置在 pandas 的 DataFrame 中的 boxplot() 函数创建一个箱线图:
df.transpose().boxplot()
这看起来几乎没问题,但有点混乱,并且没有绘制实际的数据点。
【问题讨论】:
标签: python matplotlib pandas plot