使用matplotlib绘制箱形图 [英] Draw Box-Plot with matplotlib

查看:73
本文介绍了使用matplotlib绘制箱形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用matplotlib绘制这种图表?

Is it possible to plot this kind of chart with matplotlib?

推荐答案

这在我看来很像箱线图.我创建了一个简单的图形,因为当我像这样展示我的数据时,同事经常问我这个问题

This looks a lot like a boxplot to me. I created a simple figure because colleagues often ask me about it when I am presenting my data like this

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

If this is what you are looking for, the example code would be

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

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

I have it as an IPython notebook here: https://github.com/rasbt/matplotlib-gallery

这篇关于使用matplotlib绘制箱形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆