(已经看过类似的问题,但他们没有回答这个问题)
我有一个具有以下结构的数据框 df1
{'token': {0: '180816_031', 1: '180816_031', 2: '180816_031', 3: '180816_031', 4: '180816_031', 5: '180816_031', 6: '180816_031', 7: '180816_031', 8: '180816_031', 9: '180816_031'}, 'variable': {0: 'Unnamed: 0', 1: 'adj_active_polymerase', 2: 'adj_functional_sequencing_pores', 3: 'adj_high_quality_reads', 4: 'adj_single_pores', 5: 'cell_mask_bilayers_sum', 6: 'num_align_high_quality_reads', 7: 'num_total_cells', 8: 'potential_pore', 9: 'short_pass'}, 'value': {0: 21.0, 1: 615850.51515151514, 2: 615850.51515151514, 3: 486008.39393939392, 4: 803784.06060606055, 5: 1665347.5757575757, 6: 468638.03030303027, 7: 2097152.0, 8: 1158527.0, 9: 2067189.2424242424}}
我正在使用下面的代码重新创建我的数据然后显示条形图
df1 = df.groupby(['token','variable']).agg({'value':['mean','std']})
df1.reset_index(inplace=True)
df1.sort_values('value',inplace=True,ascending=False)
fig,ax = plt.subplots()
fig.set_size_inches(16,8)
#to get different colors for each of the variable assign the variable to hue
g = sns.factorplot(x='token',y='value',data=df1, hue='variable',ax=ax, yerr='std')
#g.map_dataframe(plt.errorbar, x="followup (months)", y="probability", yerr='sd')
#Code for to put legend outside the plot
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
# Put a legend to the right of the current axis
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
# Adding respective values to the top of each bar
for p in ax.patches:
ax.annotate("%d" % p.get_height(), (p.get_x() + p.get_width() / 2, p.get_height()),
ha='center', va='center', fontsize=11, color='black', xytext=(0, 10),
textcoords='offset points',fontweight='bold')
plt.show()
在我的数据框中只使用平均值之前,我已经生成了一个输出,但是我也需要错误栏,所以我想在 yerr 中添加 std & 使用它(在阅读了这么多之后)
请帮忙。