具有最小值,最大值,平均值和标准差的箱形图

时间:2015-10-25 10:44:47

标签: python r matplotlib

我需要创建一个包含某些运行结果的箱形图 - 对于每个运行,我都有最小输出,最大输出,平均输出和标准偏差。这意味着我将需要16个带有标签的箱形图。

到目前为止我遇到的examples绘制了一个数字分布,但就我而言,这是不可行的。

有没有办法在Python(Matplotlib)/ R?

中执行此操作

1 个答案:

答案 0 :(得分:22)

@Roland上面给出的答案很重要:箱形图显示了根本不同的数量,如果你使用你拥有的数量制作类似的情节,可能会使用户感到困惑。我可能会使用堆叠的错误栏图来表示此信息。例如:

import matplotlib.pyplot as plt
import numpy as np

# construct some data like what you have:
x = np.random.randn(100, 8)
mins = x.min(0)
maxes = x.max(0)
means = x.mean(0)
std = x.std(0)

# create stacked errorbars:
plt.errorbar(np.arange(8), means, std, fmt='ok', lw=3)
plt.errorbar(np.arange(8), means, [means - mins, maxes - means],
             fmt='.k', ecolor='gray', lw=1)
plt.xlim(-1, 8)

enter image description here

相关问题