用matplotlib绘制Box-Plot

时间:2014-06-21 02:29:03

标签: python matplotlib

是否可以使用matplotlib绘制此类图表?

Plot

1 个答案:

答案 0 :(得分:4)

这看起来很像我的箱形图。我创建了一个简单的数字,因为当我提交像这样的数据

时,同事经常会问我这个问题

enter image description here

如果这是您要找的,示例代码将是

import matplotlib.pyplot as plt

x1 = [-0.46,-1.25,-2.62,0.22]
x2 = [0.24,1.88,-0.49,-0.73,-0.49]
x3 = [-0.44,0.93,0.19,-4.36,-0.88]

fig = plt.figure(figsize=(8,6))

plt.boxplot([x for x in [x1, x2, x3]], 0, 'rs', 1)
plt.xticks([y+1 for y in range(len([x1, x2, x3]))], ['x1', 'x2', 'x3'])
plt.xlabel('measurement x')
t = plt.title('Box plot')
plt.show()

enter image description here

我在这里将它作为IPython笔记本:https://github.com/rasbt/matplotlib-gallery