Я пытаюсь построить сгруппированный гистограмму с асимметричными погрешностями. Когда полоса ошибок симметрична, это дает правильную диаграмму. Однако для асимметричной версии длина полосы погрешности неверна.
Вот минимально воспроизводимый код:
# test with code from documentation
men_means, men_std = (20, 35, 30, 35, 27), (2, 3, 4, 1, 2)
women_means, women_std = (25, 32, 34, 20, 25), (3, 5, 2, 3, 3)
# dummy dataframe similar to what I will be using
avg = [20, 35, 30, 35, 27]
men_std_l = [19,33,28,34,25]
men_std_u = [22,37,31,39,29]
df = pd.DataFrame({'avg' :avg, 'low':men_std_l, 'high':men_std_u})
ind = np.arange(df.shape[0]) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind - width/2, df['avg'], width, yerr=[df['low'].values,df['high'].values], label='Men')
rects2 = ax.bar(ind + width/2, women_means, width, yerr=women_std,label='Women')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('error bar is wrong for asymmetrical, correct otherwise')
ax.legend()
fig.tight_layout()
plt.show()
Я пробовал решения из Асимметричная панель ошибок с pandas (получение ValueError: In safezip, len(args [0])=5, но len(args1)=1) и построение асимметричных полос ошибок с использованием matplotlib (получение TypeError: невозможно преобразовать данные массива из dtype('‹ U1' ) в dtype('float64') по правилу "безопасно")
Любая помощь горячо приветствуется.