Python 带有最小值、最大值、平均值和标准偏差的箱线图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33328774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Box plot with min, max, average and standard deviation
提问by Crista23
I need to create a box plot with results for some runs - for each of these runs I have the minimum output, maximum output, average output and standard deviation. This means that I will need 16 boxplots with labels.
我需要创建一个包含某些运行结果的箱线图 - 对于这些运行中的每一个,我都有最小输出、最大输出、平均输出和标准偏差。这意味着我需要 16 个带标签的箱线图。
The examplesI ran into so far plot a numerical distribution, but in my case, this is not feasible.
到目前为止,我遇到的示例绘制了一个数值分布,但就我而言,这是不可行的。
Is there any way to do this in Python (Matplotlib) / R?
有没有办法在 Python (Matplotlib) / R 中做到这一点?
回答by jakevdp
The answer given by @Roland above is important: a box plot shows fundamentally different quantities, and if you make a similar plot using the quantities you have, it might confuse users. I might represent this information using stacked errorbar plots. For example:
上面@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)