亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在堆積條形圖上適當定位注釋

在堆積條形圖上適當定位注釋

至尊寶的傳說 2022-01-11 17:00:56
我已經在堆疊的條形圖上注釋了每個條,但似乎無法使注釋與條的位置相同。這是我的代碼:for i in ax_mult.patches:  width,height=i.get_width(),i.get_height()  x,z =i.get_xy()  ax_mult.annotate(str(i.get_height()),(i.get_x()+.30*width,i.get_height()+.1*height))這就是我得到的
查看完整描述

1 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

我想您的主要問題是您將文本y有效地放置在方向上1.1 * i.get_height(),而沒有考慮初始偏移量i.get_y()。


試試這個:


for i in ax_mult.patches:

    ix,iy=i.get_x(),i.get_y() ## gives you the bottom left of each patch

    width,height=i.get_width(),i.get_height() ## the width & height of each patch


    ## to place the annotation at the center (0.5, 0.5):

    ax.annotate(str(height),(ix+0.5*width, iy+0.5*height),ha="center",va="center")


    ## alternatively via ax.text():

    # ax.text(ix+.5*width,iy+.5*height,height,ha="center",va="center" ) 

請注意,您可能需要使用良好的偏移“玩轉”,尤其是在 y 方向。該ha="center",va="center"參數正好對準在所選擇的坐標文本(同時在水平:HA和垂直:VA),其中就派上用場了,如果你想放的標簽如補丁的頂端對齊如下:


ax.annotate(str(height),(ix+0.5*width, iy+1.0*height),ha="center",va="top")

或者就在補丁的頂端上方:


ax.annotate(str(height),(ix+0.5*width, iy+1.0*height),ha="center",va="bottom")


查看完整回答
反對 回復 2022-01-11
  • 1 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號