-1
4x4シーボーンファセットグリッドの各プロットに各バーに値をオーバーレイしようとしています。以下はFactorplotで動作します。どのように私はそれをfacetgridで動作するように修正するのですか? g.axes.flat.patchesのターゲット設定もうまくいかないようです。シーボーンファセットグリッドのバーに注釈を付ける方法(ファクトプロットで動作)
# Annotate a value into each bar in each plot (Doesn't work)
# Error: AttributeError: 'numpy.flatiter' object has no attribute 'patches'
for p in g.axes.flat.patches:
g.annotate("{:.1f}".format(p.get_height()) ,
(p.get_x() + p.get_width()/2., p.get_height()-fudge), # Placement
ha='center', va='center', fontsize=12, color='white', rotation=0, xytext=(0, 20),
textcoords='offset points')
事前に感謝
(以下facetgridための短縮例)
melt =df.ix[:, np.r_[14:15, 28:29, 167:171]]
# Melt
melted = pd.melt(melt, id_vars=['region','age'],
var_name='vote_method',
value_name='popularity').dropna().sort_values(by="region")
g = sns.FacetGrid(melted, row="region", col="vote_method", hue="age",
palette=flatui,
sharex=False, sharey=True,size=10, aspect=2)
# Have to pass interval in to get keep the X axis ordered
g.map(sns.barplot, 'age', 'pref', order=melted.age.unique())
g.set_titles(size=32, fontweight='light', fontname='Helvetica Neue',
alpha=1, color= '#404040')
# Adjust the arrangement of the plots in the facetgrid
g.fig.tight_layout(pad=5)
# Annotate a value into each bar in each plot
for p in g.axes.flat.patches:
g.annotate("{:.1f}".format(p.get_height()) ,
(p.get_x() + p.get_width()/2., p.get_height()-fudge), # Placement
ha='center', va='center', fontsize=12, color='white', rotation=0, xytext=(0, 20),
textcoords='offset points')
[MCVE]を提供できますか? – ImportanceOfBeingErnest