我正在尝试从这样的DataFrame生成条形图:
I'm trying to generate bar plots from a DataFrame like this:
Pre Post Measure1 0.4 1.9这些值是我从别处计算的中值,我也有它们的方差和标准差(以及标准误差).我想将结果绘制为带有正确误差条的条形图,但为 yerr 指定多个错误值会产生异常:
These values are median values I calculated from elsewhere, and I have also their variance and standard deviation (and standard error, too). I would like to plot the results as a bar plot with the proper error bars, but specifying more than one error value to yerr yields an exception:
# Data is a DataFrame instance fig = data.plot(kind="bar", yerr=[0.1, 0.3]) [...] ValueError: In safezip, len(args[0])=1 but len(args[1])=2如果我指定了一个值(不正确),一切都很好.我怎样才能真正给每列正确的错误栏?
If I specify a single value (incorrect) all is fine. How can I actually give each column its correct error bar?
推荐答案您的数据形状是什么?
对于 n×1 数据向量,您需要一个 n×2 误差向量(正误差和负误差):
For an n-by-1 data vector, you need a n-by-2 error vector (positive error and negative error):
import pandas as pd import matplotlib.pyplot as plt df2 = pd.DataFrame([0.4, 1.9]) df2.plot(kind='bar', yerr=[[0.1, 3.0], [3.0, 0.1]]) plt.show()
更多推荐
使用 pandas 绘制带有错误条的条形图
发布评论